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

Skip to content

Commit e99f590

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

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

examples/mplot3d/surface3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
Z = np.sin(R)
2929

3030
# Plot the surface.
31-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
31+
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
3232
linewidth=0, antialiased=False)
3333

3434
# Customize the z axis.

examples/mplot3d/surface3d_demo2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
2323

2424
# Plot the surface
25-
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')
25+
ax.plot_surface(x, y, z, color='b')
2626

2727
plt.show()

examples/mplot3d/surface3d_demo3.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
colors[x, y] = colortuple[(x + y) % len(colortuple)]
3535

3636
# Plot the surface with face colors taken from the array we made.
37-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
38-
linewidth=0)
37+
surf = ax.plot_surface(X, Y, Z, facecolors=colors, linewidth=0)
3938

4039
# Customize the z axis.
4140
ax.set_zlim(-1, 1)

examples/mplot3d/surface3d_radial_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
X, Y = R*np.cos(P), R*np.sin(P)
2929

3030
# Plot the surface.
31-
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.cm.YlGnBu_r)
31+
ax.plot_surface(X, Y, Z, cmap=plt.cm.YlGnBu_r)
3232

3333
# Tweak the limits and add latex math labels.
3434
ax.set_zlim(0, 1)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,14 +1554,23 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
15541554
The `rstride` and `cstride` kwargs set the stride used to
15551555
sample the input data to generate the graph. If 1k by 1k
15561556
arrays are passed in the default values for the strides will
1557-
result in a 100x100 grid being plotted.
1557+
result in a 100x100 grid being plotted. Defaults to 10.
1558+
Superceded by `rcount` and `ccount` if both the
1559+
stride and the count are specified as of v2.0.0.
1560+
1561+
The `rcount` and `ccount` kwargs are the new method for
1562+
sampling the input data to generate the graph, and
1563+
supercedes `rstride` and `cstride` (unless using the
1564+
'classic' style) if both are specified. Added in v2.0.0.
15581565
15591566
============= ================================================
15601567
Argument Description
15611568
============= ================================================
15621569
*X*, *Y*, *Z* Data values as 2D arrays
1563-
*rstride* Array row stride (step size), defaults to 10
1564-
*cstride* Array column stride (step size), defaults to 10
1570+
*rstride* Array row stride (step size)
1571+
*cstride* Array column stride (step size)
1572+
*rcount* Use at most this many rows, defaults to 50
1573+
*ccount* Use at most this many columns, defaults to 50
15651574
*color* Color of the surface patches
15661575
*cmap* A colormap for the surface patches.
15671576
*facecolors* Face colors for the individual patches
@@ -1582,8 +1591,30 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
15821591
X, Y, Z = np.broadcast_arrays(X, Y, Z)
15831592
rows, cols = Z.shape
15841593

1594+
has_rstride = 'rstride' in kwargs
1595+
has_cstride = 'cstride' in kwargs
1596+
has_rcount = 'rcount' in kwargs
1597+
has_ccount = 'ccount' in kwargs
1598+
15851599
rstride = kwargs.pop('rstride', 10)
15861600
cstride = kwargs.pop('cstride', 10)
1601+
rcount = kwargs.pop('rcount', 50)
1602+
ccount = kwargs.pop('ccount', 50)
1603+
1604+
if rcParams['_internal.classic_mode']:
1605+
# Strides have priority over counts in classic mode.
1606+
if not has_rstride and has_rcount:
1607+
rstride = int(np.ceil(rows / rcount))
1608+
if not has_cstride and has_ccount:
1609+
cstride = int(np.ceil(cols / ccount))
1610+
else:
1611+
# If the count is provided then it has priority
1612+
# If neither count or stride is provided then use
1613+
# the default count.
1614+
if has_rcount or (not has_rstride and not has_rcount):
1615+
rstride = int(np.ceil(rows / rcount))
1616+
if has_ccount or (not has_cstride and not has_ccount):
1617+
cstride = int(np.ceil(cols / ccount))
15871618

15881619
if 'facecolors' in kwargs:
15891620
fcolors = kwargs.pop('facecolors')

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def f(t):
105105
R = np.sqrt(X ** 2 + Y ** 2)
106106
Z = np.sin(R)
107107

108-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
108+
surf = ax.plot_surface(X, Y, Z, rstride=1, ccount=40,
109109
linewidth=0, antialiased=False)
110110

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

0 commit comments

Comments
 (0)