-
Notifications
You must be signed in to change notification settings - Fork 906
/
Copy pathplot-variations.py
136 lines (116 loc) · 4.53 KB
/
plot-variations.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# -----------------------------------------------------------------------------
# Matplotlib cheat sheet
# Released under the BSD License
# -----------------------------------------------------------------------------
import sys
import pathlib
# Scripts to generate all the basic plots
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
ROOT_DIR = pathlib.Path(__file__).parent.parent
sys.path.append(str(ROOT_DIR / "fonts"))
import custom_fonts # noqa
mpl.style.use([
ROOT_DIR / 'styles/base.mplstyle',
ROOT_DIR / 'styles/plotlet.mplstyle',
])
mpl.rc('axes', titlepad=1)
subplot_kw = dict(
xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8),
)
# Basic line plot (color)
# -----------------------------------------------------------------------------
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
X = np.linspace(0, 10, 100)
Y = 4+2*np.sin(2*X)
ax.plot(X, Y, color="black", linewidth=0.75)
ax.grid()
fig.savefig(ROOT_DIR / "figures/plot-color.pdf")
# Basic line plot (linestyle)
# -----------------------------------------------------------------------------
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
X = np.linspace(0, 10, 100)
Y = 4+2*np.sin(2*X)
ax.plot(X, Y, color="C1", linewidth=0.75, linestyle="--")
ax.grid()
fig.savefig(ROOT_DIR / "figures/plot-linestyle.pdf")
# Basic line plot (linewidth)
# -----------------------------------------------------------------------------
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
X = np.linspace(0, 10, 100)
Y = 4+2*np.sin(2*X)
ax.plot(X, Y, color="C1", linewidth=1.5)
ax.grid()
fig.savefig("../figures/plot-linewidth.pdf")
fig.savefig(ROOT_DIR / "figures/plot-linewidth.pdf")
# Basic line plot (marker)
# -----------------------------------------------------------------------------
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
X = np.linspace(0, 10, 100)
Y = 4+2*np.sin(2*X)
ax.plot(X, Y, color="C1", linewidth=0.75, marker="o", markevery=5, markersize=2)
ax.grid()
fig.savefig(ROOT_DIR / "figures/plot-marker.pdf")
# Basic line plot (multi)
# -----------------------------------------------------------------------------
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
X = np.linspace(0, 10, 100)
Y1 = 4+2*np.sin(2*X)
Y2 = 4+2*np.cos(2*X)
ax.plot(X, Y1, color="C1", linewidth=0.75)
ax.plot(X, Y2, color="C0", linewidth=0.75)
ax.grid()
fig.savefig(ROOT_DIR / "figures/plot-multi.pdf")
# Basic line plot (vsplit)
# -----------------------------------------------------------------------------
(fig, [ax2, ax1]) = plt.subplots(nrows=2, gridspec_kw=dict(hspace=0.2), subplot_kw=subplot_kw)
X = np.linspace(0, 10, 100)
Y1 = 2+1*np.sin(2*X)
ax1.plot(X, Y1, color="C1", linewidth=0.75)
ax1.set_ylim(0, 4), ax1.set_yticks(np.arange(1, 4))
ax1.grid()
ax1.tick_params(axis=u'both', which=u'both', length=0)
Y2 = 2+1*np.cos(2*X)
ax2.plot(X, Y2, color="C0", linewidth=0.75)
ax2.set_ylim(0, 4), ax2.set_yticks(np.arange(1, 4))
ax2.grid()
ax2.tick_params(axis=u'both', which=u'both', length=0)
fig.savefig(ROOT_DIR / "figures/plot-vsplit.pdf")
# Basic line plot (hsplit)
# -----------------------------------------------------------------------------
(fig, [ax1, ax2]) = plt.subplots(ncols=2, gridspec_kw=dict(wspace=0.2), subplot_kw=subplot_kw)
X = np.linspace(0, 10, 100)
Y1 = 2+1*np.sin(2*X)
ax1.plot(Y1, X, color="C1", linewidth=0.75)
ax1.set_xlim(0, 4), ax1.set_xticks(np.arange(1, 4))
ax1.grid()
ax1.tick_params(axis=u'both', which=u'both', length=0)
Y2 = 2+1*np.cos(2*X)
ax2.plot(Y2, X, color="C0", linewidth=0.75)
ax2.set_xlim(0, 4), ax2.set_xticks(np.arange(1, 4))
ax2.grid()
ax2.tick_params(axis=u'both', which=u'both', length=0)
fig.savefig(ROOT_DIR / "figures/plot-hsplit.pdf")
# Basic line plot (title)
# -----------------------------------------------------------------------------
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
X = np.linspace(0, 10, 100)
Y = 3+2*np.sin(2*X)
ax.plot(X, Y, color="C1", linewidth=0.75)
ax.set_ylim(0, 6), ax.set_yticks(np.arange(1, 6))
ax.grid()
ax.set_title("A Sine wave", size=4, weight="bold")
fig.savefig(ROOT_DIR / "figures/plot-title.pdf")
# Basic line plot (xlabel)
# -----------------------------------------------------------------------------
(fig, ax) = plt.subplots(subplot_kw=subplot_kw)
X = np.linspace(0, 10, 100)
Y = 3+2*np.sin(2*X)
ax.plot(X, Y, color="C1", linewidth=0.75), ax.set_xticklabels([])
ax.set_ylim(0, 6), ax.set_yticks(np.arange(1, 6)), ax.set_yticklabels([])
ax.grid()
ax.text(4, -1, "Time", transform=ax.transData, clip_on=False,
size=3.5, ha="center", va="center")
fig.savefig(ROOT_DIR / "figures/plot-xlabel.pdf")