Skip to content

Commit dab3974

Browse files
authored
Merge pull request matplotlib#20509 from timhoffm/doc-plot-types-clean
Cleanup plot types
2 parents b2fc3e8 + 6b84212 commit dab3974

File tree

20 files changed

+60
-61
lines changed

20 files changed

+60
-61
lines changed

plot_types/arrays/contourf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
# make data
1414
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
15-
Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2)
15+
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
1616
Z = Z - Z.min()
17-
levs = np.linspace(np.min(Z), np.max(Z), 7)
17+
levels = np.linspace(np.min(Z), np.max(Z), 7)
1818

1919
# plot
2020
fig, ax = plt.subplots()
2121

22-
plt.contourf(X, Y, Z, levels=levs)
23-
plt.contour(X, Y, Z, levels=levs, colors="white", linewidths=0.5)
22+
ax.contourf(X, Y, Z, levels=levels)
23+
ax.contour(X, Y, Z, levels=levels, colors="white", linewidths=0.5)
2424

2525
plt.show()

plot_types/arrays/imshow.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
# plot
2121
fig, ax = plt.subplots()
22+
ax.grid(False)
2223

23-
ax.imshow(Z, extent=[0, 8, 0, 8], interpolation="nearest",
24-
cmap=plt.get_cmap('Blues'), vmin=0, vmax=1.6)
25-
26-
ax.set(xticks=[], yticks=[])
24+
ax.imshow(Z)
2725

2826
plt.show()

plot_types/arrays/pcolormesh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
# plot
2929
fig, ax = plt.subplots()
30+
ax.grid(False)
3031

31-
ax.pcolormesh(X, Y, Z, vmin=0, vmax=1.5, shading='nearest')
32+
ax.pcolormesh(X, Y, Z, vmin=0, vmax=1.5)
3233

3334
plt.show()

plot_types/arrays/quiver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
plt.style.use('mpl_plot_gallery')
1212

1313
# make data
14-
T = np.linspace(0, 2*np.pi, 8)
15-
X, Y = 4 + 1 * np.cos(T), 4 + 1 * np.sin(T)
16-
U, V = 1.5 * np.cos(T), 1.5 * np.sin(T)
14+
phi = np.linspace(0, 2 * np.pi, 8)
15+
x, y = 4 + 1 * np.cos(phi), 4 + 1 * np.sin(phi)
16+
u, v = 1.5 * np.cos(phi), 1.5 * np.sin(phi)
1717

1818
# plot
1919
fig, ax = plt.subplots()
2020

21-
plt.quiver(X, Y, U, V, color="C0", angles='xy',
22-
scale_units='xy', scale=0.5, width=.05)
21+
ax.quiver(x, y, u, v, color="C0", angles='xy',
22+
scale_units='xy', scale=0.5, width=.05)
2323

2424
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
2525
ylim=(0, 8), yticks=np.arange(1, 8))

plot_types/basic/bar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
# make data:
1313
np.random.seed(3)
14-
X = 0.5 + np.arange(8)
15-
Y = np.random.uniform(2, 7, len(X))
14+
x = 0.5 + np.arange(8)
15+
y = np.random.uniform(2, 7, len(x))
1616

1717
# plot
1818
fig, ax = plt.subplots()
1919

20-
ax.bar(X, Y, width=1, edgecolor="white", linewidth=0.7)
20+
ax.bar(x, y, width=1, edgecolor="white", linewidth=0.7)
2121

2222
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
2323
ylim=(0, 8), yticks=np.arange(1, 8))

plot_types/basic/pie.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313

1414
# make data
15-
X = [1, 2, 3, 4]
16-
colors = plt.get_cmap('Blues')(np.linspace(0.2, 0.7, len(X)))
15+
x = [1, 2, 3, 4]
16+
colors = plt.get_cmap('Blues')(np.linspace(0.2, 0.7, len(x)))
1717

1818
# plot
1919
fig, ax = plt.subplots()
20-
ax.pie(X, colors=colors, radius=3, center=(4, 4),
20+
ax.pie(x, colors=colors, radius=3, center=(4, 4),
2121
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)
2222

2323
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),

plot_types/basic/plot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
plt.style.use('mpl_plot_gallery')
1313

1414
# make data
15-
X = np.linspace(0, 10, 100)
16-
Y = 4 + 2 * np.sin(2 * X)
15+
x = np.linspace(0, 10, 100)
16+
y = 4 + 2 * np.sin(2 * x)
1717

1818
# plot
1919
fig, ax = plt.subplots()
2020

21-
ax.plot(X, Y, linewidth=2.0)
21+
ax.plot(x, y, linewidth=2.0)
2222

2323
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
2424
ylim=(0, 8), yticks=np.arange(1, 8))

plot_types/basic/scatter_plot.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212

1313
# make the data
1414
np.random.seed(3)
15-
X = 4 + np.random.normal(0, 2, 24)
16-
Y = 4 + np.random.normal(0, 2, len(X))
15+
x = 4 + np.random.normal(0, 2, 24)
16+
y = 4 + np.random.normal(0, 2, len(x))
1717
# size and color:
18-
S = np.random.uniform(15, 80, len(X))
18+
sizes = np.random.uniform(15, 80, len(x))
19+
colors = np.random.uniform(15, 80, len(x))
1920

2021
# plot
2122
fig, ax = plt.subplots()
2223

23-
ax.scatter(X, Y, s=S, c=-S, cmap=plt.get_cmap('Blues'), vmin=-100, vmax=0)
24+
ax.scatter(x, y, s=sizes, c=colors, vmin=-100, vmax=0)
2425

2526
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
2627
ylim=(0, 8), yticks=np.arange(1, 8))

plot_types/basic/stem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
# make data
1414
np.random.seed(3)
15-
X = 0.5 + np.arange(8)
16-
Y = np.random.uniform(2, 7, len(X))
15+
x = 0.5 + np.arange(8)
16+
y = np.random.uniform(2, 7, len(x))
1717

1818
# plot
1919
fig, ax = plt.subplots()
2020

21-
ax.stem(X, Y, bottom=0, linefmt="-", markerfmt="d")
21+
ax.stem(x, y)
2222

2323
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
2424
ylim=(0, 8), yticks=np.arange(1, 8))

plot_types/basic/step.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
# make data
1414
np.random.seed(3)
15-
X = 0.5 + np.arange(8)
16-
Y = np.random.uniform(2, 7, len(X))
15+
x = 0.5 + np.arange(8)
16+
y = np.random.uniform(2, 7, len(x))
1717

1818
# plot
1919
fig, ax = plt.subplots()
2020

21-
ax.step(X, Y, linewidth=2.5)
21+
ax.step(x, y, linewidth=2.5)
2222

2323
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
2424
ylim=(0, 8), yticks=np.arange(1, 8))

0 commit comments

Comments
 (0)