- Notifications
You must be signed in to change notification settings - Fork 908
/
Copy pathmarkers.py
59 lines (50 loc) · 2.11 KB
/
markers.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
# -----------------------------------------------------------------------------
# Matplotlib cheat sheet
# Released under the BSD License
# -----------------------------------------------------------------------------
importpathlib
importnumpyasnp
importmatplotlib.pyplotasplt
ROOT_DIR=pathlib.Path(__file__).parent.parent
# Markers
# -----------------------------------------------------------------------------
fig=plt.figure(figsize=(3.5, 1.5))
ax=fig.add_axes([0, 0, 1, 1], frameon=False,
xlim=[0.5, 10.5], ylim=[0.0, 4.35], xticks=[], yticks=[])
X=np.linspace(1, 10, 12)
Y=np.arange(1, 4)
X, Y=np.meshgrid(X, Y)
X , Y=X.ravel(), Y.ravel()
plt.scatter(X, 1+Y, s=256, marker="s", fc="C1", ec="none", alpha=.25)
markers= [
"$♠$", "$♣$", "$♥$", "$♦$", "$→$", "$←$", "$↑$", "$↓$", "$◐$", "$◑$", "$◒$", "$◓$",
"1", "2", "3", "4", "+", "x", "|", "_", 4, 5, 6, 7,
".", "o", "s", "P", "X", "*", "p", "D", "<", ">", "^", "v", ]
forx, y, markerinzip(X, Y, markers):
ify==3: fc="white"
elify==2: fc="None"
else: fc="C1"
plt.scatter(x, 1+y, s=100, marker=marker, fc=fc, ec="C1", lw=0.5)
ify==1: marker="\$%s\$"%marker
ifisinstance(marker, str): text="'%s'"%marker
else: text='%s'%marker
plt.text(x, 1+y-0.4, text,
size="x-small", ha="center", va="top", family="Monospace")
# Spacing
n_segment=4
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)
marks= [ 10, [0, -1], (25, 5), [0, 25, -1] ]
y=.6
forx0, markinzip(X0, marks):
X=np.linspace(x0, x0+segment_width, 50)
Y=y*np.ones(len(X))
ax.plot(X, Y, linewidth=1, color="black",
marker=".", mfc="white", mec="black", mew="1", markevery=mark)
ax.text((X[0]+X[-1])/2, y-0.2, '%s'%str(mark),
size="x-small", ha="center", va="top")
plt.text(.7, 1, "markevery",
size="medium", ha="left", va="center", family="Source Code Pro")
fig.savefig(ROOT_DIR/"figures/markers.pdf", dpi=600)