Skip to content

Commit ee782b1

Browse files
committed
Added rcount/ccount to plot_surface(), providing an alternative to rstride/cstride
1 parent 215fbd1 commit ee782b1

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

examples/mplot3d/surface3d_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
X, Y = np.meshgrid(X, Y)
1212
R = np.sqrt(X**2 + Y**2)
1313
Z = np.sin(R)
14-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
14+
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
1515
linewidth=0, antialiased=False)
1616
ax.set_zlim(-1.01, 1.01)
1717

examples/mplot3d/surface3d_demo2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
x = 10 * np.outer(np.cos(u), np.sin(v))
1212
y = 10 * np.outer(np.sin(u), np.sin(v))
1313
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
14-
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')
14+
ax.plot_surface(x, y, z, color='b')
1515

1616
plt.show()

examples/mplot3d/surface3d_demo3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
for x in range(xlen):
2121
colors[x, y] = colortuple[(x + y) % len(colortuple)]
2222

23-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
23+
surf = ax.plot_surface(X, Y, Z, facecolors=colors,
2424
linewidth=0)
2525

2626
ax.set_zlim3d(-1, 1)

examples/mplot3d/surface3d_radial_demo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
X, Y = R*np.cos(P), R*np.sin(P)
1919

2020
Z = ((R**2 - 1)**2)
21-
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.YlGnBu_r)
21+
ax.plot_surface(X, Y, Z, cmap=cm.YlGnBu_r)
2222
ax.set_zlim3d(0, 1)
2323
ax.set_xlabel(r'$\phi_\mathrm{real}$')
2424
ax.set_ylabel(r'$\phi_\mathrm{im}$')

lib/mpl_toolkits/mplot3d/axes3d.py

+34-3
Original file line numberDiff line numberDiff line change
@@ -1559,14 +1559,23 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
15591559
The `rstride` and `cstride` kwargs set the stride used to
15601560
sample the input data to generate the graph. If 1k by 1k
15611561
arrays are passed in the default values for the strides will
1562-
result in a 100x100 grid being plotted.
1562+
result in a 100x100 grid being plotted. Defaults to 10.
1563+
Superceded by `rcount` and `ccount` if both the
1564+
stride and the count are specified as of v2.0.0.
1565+
1566+
The `rcount` and `ccount` kwargs are the new method for
1567+
sampling the input data to generate the graph, and
1568+
supercedes `rstride` and `cstride` (unless using the
1569+
'classic' style) if both are specified. Added in v2.0.0.
15631570
15641571
============= ================================================
15651572
Argument Description
15661573
============= ================================================
15671574
*X*, *Y*, *Z* Data values as 2D arrays
1568-
*rstride* Array row stride (step size), defaults to 10
1569-
*cstride* Array column stride (step size), defaults to 10
1575+
*rstride* Array row stride (step size)
1576+
*cstride* Array column stride (step size)
1577+
*rcount* Use at most this many rows, defaults to 50
1578+
*ccount* Use at most this many columns, defaults to 50
15701579
*color* Color of the surface patches
15711580
*cmap* A colormap for the surface patches.
15721581
*facecolors* Face colors for the individual patches
@@ -1587,8 +1596,30 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
15871596
X, Y, Z = np.broadcast_arrays(X, Y, Z)
15881597
rows, cols = Z.shape
15891598

1599+
has_rstride = 'rstride' in kwargs
1600+
has_cstride = 'cstride' in kwargs
1601+
has_rcount = 'rcount' in kwargs
1602+
has_ccount = 'ccount' in kwargs
1603+
15901604
rstride = kwargs.pop('rstride', 10)
15911605
cstride = kwargs.pop('cstride', 10)
1606+
rcount = kwargs.pop('rcount', 50)
1607+
ccount = kwargs.pop('ccount', 50)
1608+
1609+
if rcParams['_internal.classic_mode']:
1610+
# Strides have priority over counts in classic mode.
1611+
if not has_rstride and has_rcount:
1612+
rstride = int(np.ceil(rows / rcount))
1613+
if not has_cstride and has_ccount:
1614+
cstride = int(np.ceil(cols / ccount))
1615+
else:
1616+
# If the count is provided then it has priority
1617+
# If neither count or stride is provided then use
1618+
# the default count.
1619+
if has_rcount or (not has_rstride and not has_rcount):
1620+
rstride = int(np.ceil(rows / rcount))
1621+
if has_ccount or (not has_cstride and not has_ccount):
1622+
cstride = int(np.ceil(cols / ccount))
15921623

15931624
if 'facecolors' in kwargs:
15941625
fcolors = kwargs.pop('facecolors')

lib/mpl_toolkits/tests/test_mplot3d.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def f(t):
107107
R = np.sqrt(X ** 2 + Y ** 2)
108108
Z = np.sin(R)
109109

110-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
110+
surf = ax.plot_surface(X, Y, Z, rstride=1, ccount=40,
111111
linewidth=0, antialiased=False)
112112

113113
ax.set_zlim3d(-1, 1)
@@ -143,7 +143,7 @@ def test_surface3d():
143143
X, Y = np.meshgrid(X, Y)
144144
R = np.sqrt(X ** 2 + Y ** 2)
145145
Z = np.sin(R)
146-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
146+
surf = ax.plot_surface(X, Y, Z, rcount=40, cstride=1, cmap=cm.coolwarm,
147147
lw=0, antialiased=False)
148148
ax.set_zlim(-1.01, 1.01)
149149
fig.colorbar(surf, shrink=0.5, aspect=5)

0 commit comments

Comments
 (0)