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

Skip to content

Commit 42df67e

Browse files
committed
FIX: make pcolormesh sample unevenly
1 parent 90fad32 commit 42df67e

File tree

12 files changed

+36
-33
lines changed

12 files changed

+36
-33
lines changed

lib/matplotlib/mpl-data/stylelib/cheatsheet_gallery.mplstyle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ figure.subplot.top: 0.99
1313

1414
# colors:
1515
image.cmap : Oranges
16-
axes.prop_cycle : cycler('color', ['ff7f0e', '1f77b4', '2ca02c'])
16+
axes.prop_cycle: cycler('color', ['FF7F0E', '1F77B4', '2CA02C'])

plot_types/A_basic/f_pie.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
import matplotlib.pyplot as plt
88
import numpy as np
99

10-
1110
# plot
1211
with plt.style.context('cheatsheet_gallery'):
1312
fig, ax = plt.subplots()
14-
13+
1514
# make data
1615
X = [1, 2, 3, 4]
1716
colors = np.zeros((len(X), 4))
@@ -28,4 +27,4 @@
2827
ax.set_ylim(0, 8)
2928
ax.set_yticks(np.arange(1, 8))
3029

31-
plt.show()
30+
plt.show()

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()

plot_types/B_arrays/d_quiver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
ax.set_ylim(0, 8)
2424
ax.set_yticks(np.arange(1, 8))
2525

26-
plt.show()
26+
plt.show()

plot_types/B_arrays/e_streamplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
# plot stream plot
2323
ax.streamplot(X[1:, 1:], Y[1:, 1:], U, V, zorder=2)
2424

25-
plt.show()
25+
plt.show()

plot_types/C_stats/a_hist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
ax.set_ylim(0, 80)
2222
ax.set_yticks(np.arange(1, 80, 10))
2323

24-
plt.show()
24+
plt.show()

plot_types/C_stats/b_boxplot.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@
1313
# plot
1414
with plt.style.context('cheatsheet_gallery'):
1515
fig, ax = plt.subplots()
16-
orange = '#ff7f0e'
1716
VP = ax.boxplot(D, positions=[2, 4, 6], widths=1.5, patch_artist=True,
1817
showmeans=False, showfliers=False,
1918
medianprops={"color": "white",
2019
"linewidth": 0.5},
21-
boxprops={"facecolor": orange,
20+
boxprops={"facecolor": "C0",
2221
"edgecolor": "white",
2322
"linewidth": 0.5},
24-
whiskerprops={"color": orange,
23+
whiskerprops={"color": "C0",
2524
"linewidth": 1.5},
26-
capprops={"color": orange,
25+
capprops={"color": "C0",
2726
"linewidth": 1.5})
2827

2928
ax.set_xlim(0, 8)
3029
ax.set_xticks(np.arange(1, 8))
3130
ax.set_ylim(0, 8)
3231
ax.set_yticks(np.arange(1, 8))
3332

34-
plt.show()
33+
plt.show()

plot_types/C_stats/c_errorbar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
with plt.style.context('cheatsheet_gallery'):
1717
fig, ax = plt.subplots()
1818

19-
ax.errorbar(X, Y, E, color="C1", linewidth=2, capsize=6)
19+
ax.errorbar(X, Y, E, linewidth=2, capsize=6)
2020

2121
ax.set_xlim(0, 8)
2222
ax.set_xticks(np.arange(1, 8))
2323
ax.set_ylim(0, 8)
2424
ax.set_yticks(np.arange(1, 8))
2525

26-
plt.show()
26+
plt.show()

plot_types/C_stats/d_violin.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
showmeans=False, showmedians=False, showextrema=False)
1919
#style:
2020
for body in VP['bodies']:
21+
2122
body.set_alpha(0.9)
2223

23-
ax.set_xlim(0, 8)
24-
ax.set_xticks(np.arange(1, 8))
25-
ax.set_ylim(0, 8)
26-
ax.set_yticks(np.arange(1, 8))
24+
ax.set_xlim(0, 8)
25+
ax.set_xticks(np.arange(1, 8))
26+
ax.set_ylim(0, 8)
27+
ax.set_yticks(np.arange(1, 8))
2728

28-
plt.show()
29+
plt.show()

plot_types/C_stats/f_eventplot.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
with plt.style.context('cheatsheet_gallery'):
1616
fig, ax = plt.subplots()
1717

18-
ax.eventplot(D, colors="C0", orientation="vertical",
19-
lineoffsets=X, linewidth=0.75)
18+
ax.eventplot(D, orientation="vertical", lineoffsets=X, linewidth=0.75)
2019

2120
ax.set_xlim(0, 8)
2221
ax.set_xticks(np.arange(1, 8))
2322
ax.set_ylim(0, 8)
2423
ax.set_yticks(np.arange(1, 8))
2524

26-
plt.show()
25+
plt.show()

plot_types/C_stats/g_hist2d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
ax.hist2d(x, y, bins=(np.arange(-3, 3, 0.1), np.arange(-3, 3, 0.1)))
1919

20-
ax.set_xlim(-2, 2)
21-
ax.set_ylim(-3, 3)
20+
ax.set_xlim(-2, 2)
21+
ax.set_ylim(-3, 3)
2222

23-
plt.show()
23+
plt.show()

plot_types/C_stats/h_hexbin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
ax.hexbin(x, y, gridsize=20)
1919

20-
ax.set_xlim(-2, 2)
21-
ax.set_ylim(-3, 3)
20+
ax.set_xlim(-2, 2)
21+
ax.set_ylim(-3, 3)
2222

23-
plt.show()
23+
plt.show()

0 commit comments

Comments
 (0)