Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72f35a4

Browse files
committed
FIX: make pcolormesh sample unevenly
1 parent 39d276f commit 72f35a4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

plot_types/B_arrays/b_pcolormesh.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@
1010
import matplotlib.pyplot as plt
1111
import numpy as np
1212

13-
# make data
13+
# make full-res data
1414
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
1515
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
1616
Z = Z - Z.min()
1717

18+
# sample unevenly in x:
19+
dx = np.sqrt((np.arange(16) - 8)**2) + 6
20+
dx = np.floor(dx / sum(dx) * 255)
21+
xint = np.cumsum(dx).astype('int')
22+
X = X[0, xint]
23+
Y = Y[::8, 0]
24+
Z = Z[::8,:][:, xint]
25+
1826
# plot
1927
with plt.style.context('cheatsheet_gallery'):
2028
fig, ax = plt.subplots()
2129

2230
# plot:
23-
ax.pcolormesh(X, Y, Z, vmin=0, vmax=1.1)
24-
25-
#ax.set_ylim(np.min(Y), np.max(Y))
26-
#ax.set_xlim(np.min(X), np.max(X))
31+
ax.pcolormesh(X, Y, Z, vmin=0, vmax=1.5)
2732
plt.show()

0 commit comments

Comments
 (0)