Skip to content

Commit ce8342f

Browse files
committed
Simplify data generation for imshow and pcolormesh plot_types
1 parent 9b58d8e commit ce8342f

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

plot_types/arrays/imshow.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
plt.style.use('_mpl-gallery-nogrid')
1313

1414
# make data
15-
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
15+
X, Y = np.meshgrid(np.linspace(-3, 3, 16), np.linspace(-3, 3, 16))
1616
Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
17-
Z = Z[::16, ::16]
1817

1918
# plot
2019
fig, ax = plt.subplots()

plot_types/arrays/pcolormesh.py

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

1313
plt.style.use('_mpl-gallery-nogrid')
1414

15-
# make full-res data
16-
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
15+
# make data with uneven sampling in x
16+
x = [-3, -2, -1.6, -1.2, -.8, -.5, -.2, .1, .3, .5, .8, 1.1, 1.5, 1.9, 2.3, 3]
17+
X, Y = np.meshgrid(x, np.linspace(-3, 3, 128))
1718
Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
1819

19-
# sample unevenly in x:
20-
dx = np.sqrt((np.arange(16) - 8)**2) + 6
21-
dx = np.floor(dx / sum(dx) * 255)
22-
xint = np.cumsum(dx).astype('int')
23-
X = X[0, xint]
24-
Y = Y[::8, 0]
25-
Z = Z[::8, :][:, xint]
26-
2720
# plot
2821
fig, ax = plt.subplots()
2922

0 commit comments

Comments
 (0)