Skip to content

Commit 44f015c

Browse files
committed
Replace step with stairs and correct subplot_adjusts
1 parent 56c1693 commit 44f015c

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

cheatsheets.tex

+7-8
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,13 @@
432432
\vspace{\fill}
433433
% --- Advanced plots --------------------------------------------------------
434434
\begin{myboxed}{Advanced plots}
435-
\plot{advanced-step.pdf}{\textbf{step}(X,Y,[fmt],…)}
436-
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.step.html}
437-
{\mandatory{X},
438-
\mandatory{Y},
439-
\optional{fmt},
440-
\optional{color},
441-
\optional{marker},
442-
\optional{where} }
435+
\plot{advanced-stairs.pdf}{\textbf{stairs}(Y,[edges],…)}
436+
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.stairs.html}
437+
{\mandatory{Y},
438+
\optional{edges},
439+
\optional{orientation},
440+
\optional{baseline},
441+
\optional{fill} }
443442
{}
444443
\plot{advanced-boxplot.pdf}{\textbf{boxplot}(X,…)}
445444
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.boxplot.html}

scripts/adjustements.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,38 @@
4848

4949
# Window size extension
5050
X, Y = [0, 0], [0, -8]
51-
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
51+
plt.plot(X, Y, color="gray", zorder=0, linewidth=1, clip_on=False)
5252

5353
X, Y = [100, 100], [0, -8]
54-
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
54+
plt.plot(X, Y, color="gray", zorder=0, linewidth=1, clip_on=False)
5555

5656
X, Y = [100, 108], [0, 0]
57-
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
57+
plt.plot(X, Y, color="gray", zorder=0, linewidth=1, clip_on=False)
5858

5959
X, Y = [100, 108], [75, 75]
60-
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
60+
plt.plot(X, Y, color="gray", zorder=0, linewidth=1, clip_on=False)
6161

6262

6363
def ext_arrow(p0, p1, p2, p3):
6464
p0, p1 = np.asarray(p0), np.asarray(p1)
6565
p2, p3 = np.asarray(p2), np.asarray(p3)
6666
ax.arrow(*p0, *(p1-p0), zorder=20, linewidth=0,
6767
length_includes_head=True, width=.4,
68-
head_width=2, head_length=2, color="black")
68+
head_width=2, head_length=2, color="gray")
6969
ax.arrow(*p3, *(p2-p3), zorder=20, linewidth=0,
7070
length_includes_head=True, width=.4,
71-
head_width=2, head_length=2, color="black")
72-
plt.plot([p1[0], p2[0]], [p1[1], p2[1]], linewidth=.9, color="black")
71+
head_width=2, head_length=2, color="gray")
72+
plt.plot([p1[0], p2[0]], [p1[1], p2[1]], zorder=20, linewidth=.9, color="gray")
7373

7474

7575
def int_arrow(p0, p1):
7676
p0, p1 = np.asarray(p0), np.asarray(p1)
7777
ax.arrow(*((p0+p1)/2), *((p1-p0)/2), zorder=20, linewidth=0,
7878
length_includes_head=True, width=.4,
79-
head_width=2, head_length=2, color="black")
79+
head_width=2, head_length=2, color="gray")
8080
ax.arrow(*((p0+p1)/2), *(-(p1-p0)/2), zorder=20, linewidth=0,
8181
length_includes_head=True, width=.4,
82-
head_width=2, head_length=2, color="black")
82+
head_width=2, head_length=2, color="gray")
8383

8484

8585
x = 0
@@ -91,22 +91,24 @@ def int_arrow(p0, p1):
9191
ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) )
9292
ax.text(x-4.5, y, "wspace", ha="right", va="center", size="x-small", zorder=20)
9393

94-
x += 45
95-
ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) )
96-
ax.text(x-4.5, y, "right", ha="right", va="center", size="x-small", zorder=20)
94+
y=20
95+
int_arrow( (0, y), (95, y))
96+
ax.text(80, y, "right", backgroundcolor="white", ha="right", va="center",
97+
size="x-small", zorder=30)
9798

9899
y = 0
99-
x = 25
100+
x = 22.5
100101
ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) )
101102
ax.text(x, y+9.5, "bottom", ha="center", va="bottom", size="x-small", zorder=20)
102103

103104
y += 35
104105
ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) )
105106
ax.text(x, y-4.5, "hspace", ha="center", va="top", size="x-small", zorder=20)
106107

107-
y += 35
108-
ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) )
109-
ax.text(x, y-4.5, "top", ha="center", va="top", size="x-small", zorder=20)
108+
x = 31
109+
int_arrow( (x, 0), (x, 70))
110+
ax.text(x, 55, "top", backgroundcolor="white", rotation="vertical",
111+
ha="center", va="center", size="x-small", zorder=30)
110112

111113
int_arrow((0, -5), (100, -5))
112114
ax.text(50, -5, "figure width", backgroundcolor="white", zorder=30,

scripts/advanced-plots.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
55

6-
# Scripts to generate all the basic plots
6+
# Scripts to generate all the advanced plots
77
import numpy as np
88
import matplotlib as mpl
99
import matplotlib.pyplot as plt
@@ -15,15 +15,17 @@
1515
d = 0.01
1616
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
1717

18-
# Step plot
18+
# Stairs plot
1919
# -----------------------------------------------------------------------------
20-
X = np.linspace(0, 10, 16)
21-
Y = 4 + 2*np.sin(2*X)
22-
ax.step(X, Y, color="C1", linewidth=0.75)
20+
X = np.linspace(0, 2*np.pi, 9)
21+
Y = 2*np.sin(3*X)
22+
Y[7:] = 0
23+
ax.stairs(Y, color="C1", linewidth=0.75)
2324
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
24-
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
25+
ax.set_ylim(-4, 4), ax.set_yticks(np.arange(-4, 4))
26+
ax.set_axisbelow(True)
2527
ax.grid(linewidth=0.125)
26-
plt.savefig("../figures/advanced-step.pdf")
28+
plt.savefig("../figures/advanced-stairs.pdf")
2729
ax.clear()
2830

2931
# Violin plot

0 commit comments

Comments
 (0)