Skip to content

Commit 7ed77e4

Browse files
committed
Merge pull request #7087 from rougier/linestyle
DOC: Example of user-defined linestyle (TikZ linestyle)
1 parent 2ddc50e commit 7ed77e4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Different linestyles copying those of Tikz/PGF
3+
"""
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
from collections import OrderedDict
7+
8+
linestyles = OrderedDict(
9+
[('solid', (0, ())),
10+
('loosely dotted', (0, (1, 10))),
11+
('dotted', (0, (1, 5))),
12+
('densely dotted', (0, (1, 1))),
13+
14+
('loosely dashed', (0, (5, 10))),
15+
('dashed', (0, (5, 5))),
16+
('densely dashed', (0, (5, 1))),
17+
18+
('loosely dashdotted', (0, (3, 10, 1, 10))),
19+
('dashdotted', (0, (3, 5, 1, 5))),
20+
('densely dashdotted', (0, (3, 1, 1, 1))),
21+
22+
('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
23+
('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))),
24+
('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))])
25+
26+
27+
plt.figure(figsize=(10, 6))
28+
ax = plt.subplot(1, 1, 1)
29+
30+
X, Y = np.linspace(0, 100, 10), np.zeros(10)
31+
for i, (name, linestyle) in enumerate(linestyles.items()):
32+
ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black')
33+
34+
ax.set_ylim(-0.5, len(linestyles)-0.5)
35+
plt.yticks(np.arange(len(linestyles)), linestyles.keys())
36+
plt.xticks([])
37+
38+
for i, (name, linestyle) in enumerate(linestyles.items()):
39+
ax.text(-0.5, i-0.4, str(linestyle), fontsize=8, ha="right",
40+
color="blue", family="monospace")
41+
42+
plt.tight_layout()
43+
plt.show()

0 commit comments

Comments
 (0)