Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d7ba921

Browse filesBrowse files
committed
Added linestyles example
1 parent f16a2c9 commit d7ba921
Copy full SHA for d7ba921

File tree

Expand file treeCollapse file tree

1 file changed

+45
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+45
-0
lines changed
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.savefig("linestyles.pdf")
44+
plt.savefig("linestyles.png", dpi=150)
45+
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.