-
Notifications
You must be signed in to change notification settings - Fork 906
/
Copy pathlinestyles.py
65 lines (52 loc) · 2.2 KB
/
linestyles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -----------------------------------------------------------------------------
# Matplotlib cheat sheet
# Released under the BSD License
# -----------------------------------------------------------------------------
import sys
import pathlib
import numpy as np
import matplotlib.pyplot as plt
ROOT_DIR = pathlib.Path(__file__).parent.parent
sys.path.append(str(ROOT_DIR / "fonts"))
import custom_fonts # noqa
fig = plt.figure(figsize=(4.25, 2*.55))
ax = fig.add_axes([0, 0, 1, 1], xlim=[0.75, 10.25], ylim=[0.5, 2.5], frameon=False,
xticks=[], yticks=[])
y = 2
def split(n_segment):
width = 9
segment_width = 0.75*(width/n_segment)
segment_pad = (width - n_segment*segment_width)/(n_segment-1)
X0 = 1+np.arange(n_segment)*(segment_width+segment_pad)
X1 = X0 + segment_width
return X0, X1
# Line style
# ----------------------------------------------------------------------------
X0, X1 = split(5)
styles = "-", ":", "--", "-.", (0, (0.01, 2))
for x0, x1, style in zip(X0, X1, styles):
ax.plot([x0, x1], [y, y], color="C1", linestyle=style,
solid_capstyle="round", dash_capstyle="round", linewidth=3)
if isinstance(style, str): text = '"%s"' % style
else: text = '%s' % str(style)
text = text.replace(' ', '')
ax.text((x0+x1)/2, y-0.2, text,
size=8, ha="center", va="top", family="Source Code Pro")
ax.text(X0[0]-0.25, y+0.2, "linestyle or ls", family="Source Code Pro",
size=14, ha="left", va="baseline")
y -= 1
# Dash capstyle
# ----------------------------------------------------------------------------
X0, X1 = split(3)
styles = "butt", "round", "projecting"
for x0, x1, style in zip(X0, X1, styles):
ax.plot([x0, x1], [y, y], color="C1", dash_capstyle="projecting",
linewidth=7, linestyle="--", alpha=.25)
ax.plot([x0, x1], [y, y], color="C1", linewidth=7,
linestyle="--", dash_capstyle=style)
ax.text((x0+x1)/2, y-0.2, '"%s"' % style, family="Source Code Pro",
size=10, ha="center", va="top")
ax.text(X0[0]-0.25, y+0.2, "capstyle or dash_capstyle", family="Source Code Pro",
size=14, ha="left", va="baseline")
fig.savefig(ROOT_DIR / "figures/linestyles.pdf", dpi=200)
# plt.show()