|
3 | 3 | Linestyles
|
4 | 4 | ==========
|
5 | 5 |
|
6 |
| -This example showcases different linestyles copying those of Tikz/PGF. |
7 |
| -Linestyle can be provided as simple as *solid* , *dotted* or *dashed*. |
8 |
| -Moreover, the dashing of the line can be controlled by a dash tuple |
9 |
| -such as (offset, (on_off_seq)) as mentioned in `.Line2D.set_linestyle`. |
10 |
| -For e.g., ``(0, (3, 10, 1, 15))`` means 3pt-line,10pt-space,1pt-line,15pt-space |
11 |
| -with no offset. |
| 6 | +Linestyle can be provided as simple as *solid* , *dotted*, *dashed* |
| 7 | +or *dashdot*. Moreover, the dashing of the line can be controlled by |
| 8 | +a dash tuple such as (offset, (on_off_seq)) as mentioned in |
| 9 | +`.Line2D.set_linestyle`. For e.g., ``(0, (3, 10, 1, 15))`` means |
| 10 | + 3pt-line,10pt-space,1pt-line,15pt-space with no offset. |
12 | 11 |
|
13 | 12 | *Note*: The dash style can also be configured via `.Line2D.set_dashes`
|
14 | 13 | as shown in :doc:`/gallery/lines_bars_and_markers/line_demo_dash_control`
|
|
21 | 20 | from matplotlib.transforms import blended_transform_factory
|
22 | 21 |
|
23 | 22 | linestyles = [
|
24 |
| - ('solid', ('-')), # Same as (0, ()) |
25 |
| - ('dotted', (':')), # Same as (0, (1, 1)) |
26 |
| - ('dashed', ('--')), |
27 |
| - ('dashdot', ('-.')), |
| 23 | + ('solid', ('solid')), # Same as (0, ()) or '-' |
| 24 | + ('dotted', ('dotted')), # Same as (0, (1, 1)) or '.' |
| 25 | + ('dashed', ('dashed')), # Same as '--' |
| 26 | + ('dashdot', ('dashdot')), # Same as '-.' |
28 | 27 |
|
29 |
| - ('loosely dotted', (0, (1, 10))), |
30 |
| - ('densely dotted', (0, (1, 1))), |
| 28 | + ('loosely dotted', (0, (1, 10))), |
| 29 | + ('densely dotted', (0, (1, 1))), |
31 | 30 |
|
32 |
| - ('loosely dashed', (0, (5, 10))), |
33 |
| - ('densely dashed', (0, (5, 1))), |
| 31 | + ('loosely dashed', (0, (5, 10))), |
| 32 | + ('densely dashed', (0, (5, 1))), |
34 | 33 |
|
35 |
| - ('loosely dashdotted', (0, (3, 10, 1, 10))), |
36 |
| - ('densely dashdotted', (0, (3, 1, 1, 1))), |
| 34 | + ('loosely dashdotted', (0, (3, 10, 1, 10))), |
| 35 | + ('densely dashdotted', (0, (3, 1, 1, 1))), |
37 | 36 |
|
38 |
| - ('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))), |
| 37 | + ('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))), |
39 | 38 | ('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
|
40 | 39 | ('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))]
|
41 | 40 |
|
42 | 41 | # Reverse the list so that plots and linestyles are in same order.
|
43 | 42 | linestyles = OrderedDict(linestyles[::-1])
|
44 |
| - |
45 |
| -plt.figure(figsize=(10, 6)) |
46 |
| -ax = plt.subplot(1, 1, 1) |
47 |
| - |
48 | 43 | X, Y = np.linspace(0, 100, 10), np.zeros(10)
|
| 44 | + |
| 45 | +fig, ax = plt.subplots(figsize=(10, 6)) |
49 | 46 | for i, (name, linestyle) in enumerate(linestyles.items()):
|
50 | 47 | ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black')
|
51 | 48 |
|
52 |
| -ax.set_ylim(-0.5, len(linestyles)-0.5) |
53 |
| -plt.yticks(np.arange(len(linestyles)), linestyles.keys()) |
54 |
| -plt.xticks([]) |
| 49 | +ax.set(xticks=[], ylim=(-0.5, len(linestyles)-0.5), |
| 50 | + yticks=np.arange(len(linestyles)), yticklabels=linestyles.keys()) |
55 | 51 |
|
56 | 52 | # For each line style, add a text annotation with a small offset from
|
57 | 53 | # the reference point (0 in Axes coords, y tick value in Data coords).
|
|
0 commit comments