|
8 | 8 | import matplotlib as mpl |
9 | 9 | import matplotlib.pyplot as plt |
10 | 10 |
|
11 | | -fig = plt.figure(figsize=(0.4,0.4)) |
| 11 | +fig = plt.figure(figsize=(0.4, 0.4)) |
12 | 12 | mpl.rcParams['axes.linewidth'] = 0.5 |
13 | 13 | mpl.rcParams['xtick.major.size'] = 0.0 |
14 | 14 | mpl.rcParams['ytick.major.size'] = 0.0 |
15 | 15 | d = 0.01 |
16 | | -ax = fig.add_axes([d,d,1-2*d,1-2*d]) |
| 16 | +ax = fig.add_axes([d, d, 1 - 2 * d, 1 - 2 * d]) |
17 | 17 |
|
18 | 18 | # Basic line plot |
19 | 19 | # ----------------------------------------------------------------------------- |
20 | 20 | X = np.linspace(0, 10, 100) |
21 | | -Y = 4+2*np.sin(2*X) |
| 21 | +Y = 4 + 2*np.sin(2*X) |
22 | 22 | ax.plot(X, Y, color="C1", linewidth=0.75) |
23 | | -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)) |
| 23 | +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 | 25 | ax.grid(linewidth=0.125) |
26 | 26 | plt.savefig("../figures/basic-plot.pdf") |
27 | 27 | ax.clear() |
28 | 28 |
|
| 29 | +# Basic line plot (color)blaPwd |
29 | 30 |
|
30 | | -# Basic line plot (color) |
31 | 31 | # ----------------------------------------------------------------------------- |
32 | 32 | X = np.linspace(0, 10, 100) |
33 | | -Y = 4+2*np.sin(2*X) |
| 33 | +Y = 4 + 2 * np.sin(2 * X) |
34 | 34 | ax.plot(X, Y, color="black", linewidth=0.75) |
35 | | -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) |
36 | | -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) |
| 35 | +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) |
| 36 | +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) |
37 | 37 | ax.grid(linewidth=0.125) |
38 | 38 | plt.savefig("../figures/basic-plot-color.pdf") |
39 | 39 | ax.clear() |
40 | 40 |
|
41 | 41 | # Basic scatter plot |
42 | 42 | # ----------------------------------------------------------------------------- |
43 | 43 | np.random.seed(3) |
44 | | -X = 4+np.random.normal(0, 1.25, 24) |
45 | | -Y = 4+np.random.normal(0, 1.25, len(X)) |
| 44 | +X = 4 + np.random.normal(0, 1.25, 24) |
| 45 | +Y = 4 + np.random.normal(0, 1.25, len(X)) |
46 | 46 | ax.scatter(X, Y, 5, zorder=10, |
47 | 47 | edgecolor="white", facecolor="C1", linewidth=0.25) |
48 | | -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) |
49 | | -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) |
| 48 | +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) |
| 49 | +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) |
50 | 50 | ax.grid(linewidth=0.125) |
51 | 51 | plt.savefig("../figures/basic-scatter.pdf") |
52 | 52 | ax.clear() |
|
58 | 58 | Y = np.random.uniform(2, 7, len(X)) |
59 | 59 | ax.bar(X, Y, bottom=0, width=1, |
60 | 60 | edgecolor="white", facecolor="C1", linewidth=0.25) |
61 | | -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) |
62 | | -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) |
| 61 | +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) |
| 62 | +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) |
63 | 63 | ax.set_axisbelow(True) |
64 | 64 | ax.grid(linewidth=0.125) |
65 | 65 | plt.savefig("../figures/basic-bar.pdf") |
66 | 66 | ax.clear() |
67 | 67 |
|
68 | | - |
69 | 68 | # Basic imshow plot |
70 | 69 | # ----------------------------------------------------------------------------- |
71 | 70 | np.random.seed(3) |
72 | | -I = np.zeros((8,8,4)) |
| 71 | +I = np.zeros((8, 8, 4)) |
73 | 72 | I[:,:] = mpl.colors.to_rgba("C1") |
74 | | -I[...,3] = np.random.uniform(0.25,1.0,(8,8)) |
75 | | -ax.imshow(I, extent=[0,8,0,8], interpolation="nearest") |
76 | | -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) |
77 | | -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) |
| 73 | +I[...,3] = np.random.uniform(0.25, 1.0, (8, 8)) |
| 74 | +ax.imshow(I, extent=[0, 8, 0, 8], interpolation="nearest") |
| 75 | +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) |
| 76 | +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) |
78 | 77 | ax.grid(linewidth=0.25, color="white") |
79 | 78 | plt.savefig("../figures/basic-imshow.pdf") |
80 | 79 | ax.clear() |
|
83 | 82 | # ----------------------------------------------------------------------------- |
84 | 83 | np.random.seed(1) |
85 | 84 | X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256)) |
86 | | -Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2) |
| 85 | +Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2) |
87 | 86 | Z = Z - Z.min() |
88 | 87 | plt.pcolormesh(X, Y, Z, cmap='Oranges', shading='auto') |
89 | 88 | ax.set_xlim(-3, 3), ax.set_xticks(np.arange(-3, 4)) |
90 | | -ax.set_ylim(-3, 3), ax.set_yticks(np.arange(-3,4)) |
| 89 | +ax.set_ylim(-3, 3), ax.set_yticks(np.arange(-3, 4)) |
91 | 90 | plt.savefig("../figures/basic-pcolormesh.pdf") |
92 | 91 | ax.clear() |
93 | 92 |
|
94 | 93 | # Basic contour plot |
95 | 94 | # ----------------------------------------------------------------------------- |
96 | | -colors = np.zeros((5,4)) |
| 95 | +colors = np.zeros((5, 4)) |
97 | 96 | colors[:] = mpl.colors.to_rgba("C1") |
98 | | -colors[:,3] = np.linspace(0.15, 0.85, len(colors)) |
99 | | -plt.contourf(Z, len(colors), extent=[0,8,0,8], colors=colors) |
100 | | -plt.contour(Z, len(colors), extent=[0,8,0,8], colors="white", linewidths=0.125, |
101 | | - nchunk=10) |
102 | | -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) |
103 | | -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) |
| 97 | +colors[:, 3] = np.linspace(0.15, 0.85, len(colors)) |
| 98 | +plt.contourf(Z, len(colors), extent=[0, 8, 0, 8], colors=colors) |
| 99 | +plt.contour(Z, len(colors), extent=[0, 8, 0, 8], colors="white", |
| 100 | + linewidths=0.125, nchunk=10) |
| 101 | +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) |
| 102 | +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) |
104 | 103 | plt.savefig("../figures/basic-contour.pdf") |
105 | 104 | ax.clear() |
106 | 105 |
|
107 | | - |
108 | 106 | # Basic pie plot |
109 | 107 | # ----------------------------------------------------------------------------- |
110 | | -X = 1,2,3,4 |
111 | | -colors = np.zeros((len(X),4)) |
| 108 | +X = [1, 2, 3, 4] |
| 109 | +colors = np.zeros((len(X), 4)) |
112 | 110 | colors[:] = mpl.colors.to_rgba("C1") |
113 | | -colors[:,3] = np.linspace(0.25, 0.75, len(X)) |
114 | | -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) |
115 | | -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) |
| 111 | +colors[:, 3] = np.linspace(0.25, 0.75, len(X)) |
| 112 | +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) |
| 113 | +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) |
116 | 114 | ax.set_axisbelow(True) |
117 | 115 | ax.grid(linewidth=0.25, color="0.75") |
118 | | -ax.pie(X, colors=["white",]*len(X), radius=3, center=(4,4), |
119 | | - wedgeprops = {"linewidth": 0.25, "edgecolor": "white"}, frame=True) |
120 | | -ax.pie(X, colors=colors, radius=3, center=(4,4), |
121 | | - wedgeprops = {"linewidth": 0.25, "edgecolor": "white"}, frame=True) |
| 116 | +ax.pie(X, colors=["white"] * len(X), radius=3, center=(4, 4), |
| 117 | + wedgeprops={"linewidth": 0.25, "edgecolor": "white"}, frame=True) |
| 118 | +ax.pie(X, colors=colors, radius=3, center=(4, 4), |
| 119 | + wedgeprops={"linewidth": 0.25, "edgecolor": "white"}, frame=True) |
122 | 120 | plt.savefig("../figures/basic-pie.pdf") |
123 | 121 | ax.clear() |
124 | 122 |
|
125 | | - |
126 | 123 | # Basic text plot |
127 | 124 | # ----------------------------------------------------------------------------- |
128 | | -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) |
129 | | -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) |
| 125 | +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) |
| 126 | +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) |
130 | 127 | ax.set_axisbelow(True) |
131 | 128 | ax.grid(linewidth=0.25, color="0.75") |
132 | 129 | ax.text(4, 4, "TEXT", color="C1", size=8, weight="bold", |
|
142 | 139 | Y2 = 1 + 2*X/8 + np.random.uniform(0.0, 0.5, len(X)) |
143 | 140 | plt.fill_between(X, Y1, Y2, color="C1", alpha=.5, linewidth=0) |
144 | 141 | plt.plot(X, (Y1+Y2)/2, color="C1", linewidth=0.5) |
145 | | -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) |
146 | | -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) |
| 142 | +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) |
| 143 | +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) |
147 | 144 | ax.set_axisbelow(True) |
148 | 145 | ax.grid(linewidth=0.125, color="0.75") |
149 | 146 | plt.savefig("../figures/basic-fill.pdf") |
|
153 | 150 | # ----------------------------------------------------------------------------- |
154 | 151 | np.random.seed(1) |
155 | 152 | T = np.linspace(0, 2*np.pi, 8) |
156 | | -X, Y = 4 + 1*np.cos(T), 4 + 1*np.sin(T) |
| 153 | +X, Y = 4 + np.cos(T), 4 + np.sin(T) |
157 | 154 | U, V = 1.5*np.cos(T), 1.5*np.sin(T) |
158 | 155 | plt.quiver(X, Y, U, V, color="C1", |
159 | 156 | angles='xy', scale_units='xy', scale=0.5, width=.05) |
160 | | -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) |
161 | | -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) |
| 157 | +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) |
| 158 | +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) |
162 | 159 | ax.set_axisbelow(True) |
163 | 160 | ax.grid(linewidth=0.125, color="0.75") |
164 | 161 | plt.savefig("../figures/basic-quiver.pdf") |
|
0 commit comments