|
3 | 3 | Linestyles
|
4 | 4 | ==========
|
5 | 5 |
|
6 |
| -This examples showcases different linestyles copying those of Tikz/PGF. |
| 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. |
| 12 | +
|
| 13 | +*Note*: The dash style can also be configured via `.Line2D.set_dashes` |
| 14 | +as shown in :doc:`/gallery/lines_bars_and_markers/line_demo_dash_control` |
| 15 | +and passing a list of dash sequences using the keyword *dashes* to the |
| 16 | +cycler in :doc:`property_cycle </tutorials/intermediate/color_cycle>`. |
7 | 17 | """
|
8 | 18 | import numpy as np
|
9 | 19 | import matplotlib.pyplot as plt
|
10 | 20 | from collections import OrderedDict
|
11 | 21 | from matplotlib.transforms import blended_transform_factory
|
12 | 22 |
|
13 |
| -linestyles = OrderedDict( |
14 |
| - [('solid', (0, ())), |
| 23 | +linestyles = [ |
| 24 | + ('solid', ('-')), # Same as (0, ()) |
| 25 | + ('dotted', (':')), # Same as (0, (1, 1)) |
| 26 | + ('dashed', ('--')), |
| 27 | + ('dashdot', ('-.')), |
| 28 | + |
15 | 29 | ('loosely dotted', (0, (1, 10))),
|
16 |
| - ('dotted', (0, (1, 5))), |
17 | 30 | ('densely dotted', (0, (1, 1))),
|
18 | 31 |
|
19 | 32 | ('loosely dashed', (0, (5, 10))),
|
20 |
| - ('dashed', (0, (5, 5))), |
21 | 33 | ('densely dashed', (0, (5, 1))),
|
22 | 34 |
|
23 | 35 | ('loosely dashdotted', (0, (3, 10, 1, 10))),
|
24 |
| - ('dashdotted', (0, (3, 5, 1, 5))), |
25 | 36 | ('densely dashdotted', (0, (3, 1, 1, 1))),
|
26 | 37 |
|
| 38 | + ('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))), |
27 | 39 | ('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
|
28 |
| - ('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))), |
29 |
| - ('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))]) |
| 40 | + ('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))] |
30 | 41 |
|
| 42 | +# Reverse the list so that plots and linestyles are in same order. |
| 43 | +linestyles = OrderedDict(linestyles[::-1]) |
31 | 44 |
|
32 | 45 | plt.figure(figsize=(10, 6))
|
33 | 46 | ax = plt.subplot(1, 1, 1)
|
|
44 | 57 | # the reference point (0 in Axes coords, y tick value in Data coords).
|
45 | 58 | reference_transform = blended_transform_factory(ax.transAxes, ax.transData)
|
46 | 59 | for i, (name, linestyle) in enumerate(linestyles.items()):
|
47 |
| - ax.annotate(str(linestyle), xy=(0.0, i), xycoords=reference_transform, |
| 60 | + ax.annotate(repr(linestyle), xy=(0.0, i), xycoords=reference_transform, |
48 | 61 | xytext=(-6, -12), textcoords='offset points', color="blue",
|
49 | 62 | fontsize=8, ha="right", family="monospace")
|
50 | 63 |
|
|
0 commit comments