Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 42a143c

Browse filesBrowse files
committed
Merge pull request #4852 from jenshnielsen/nullstrideswireframe
ENH: Null strides wireframe
2 parents 263c06a + 0a252bb commit 42a143c
Copy full SHA for 42a143c

File tree

Expand file treeCollapse file tree

6 files changed

+77
-9
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+77
-9
lines changed

‎doc/users/whats_new/wireframe3d.rst

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Zero r/cstride support in plot_wireframe
2+
----------------------------------------
3+
4+
Adam Hughes added support to mplot3d's plot_wireframe to draw only row or
5+
column line plots.
6+
7+
8+
Example::
9+
10+
from mpl_toolkits.mplot3d import Axes3D, axes3d
11+
fig = plt.figure()
12+
ax = fig.add_subplot(111, projection='3d')
13+
X, Y, Z = axes3d.get_test_data(0.05)
14+
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=0)
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from mpl_toolkits.mplot3d import axes3d
2+
import matplotlib.pyplot as plt
3+
import numpy as np
4+
5+
fig, [ax1, ax2] = plt.subplots(2, 1, figsize=(8, 12), subplot_kw={'projection': '3d'})
6+
X, Y, Z = axes3d.get_test_data(0.05)
7+
ax1.plot_wireframe(X, Y, Z, rstride=10, cstride=0)
8+
ax1.set_title("Column stride 0")
9+
ax2.plot_wireframe(X, Y, Z, rstride=0, cstride=10)
10+
ax2.set_title("Row stride 0")
11+
plt.tight_layout()
12+
plt.show()

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+19-8Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,9 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
17171717
Plot a 3D wireframe.
17181718
17191719
The `rstride` and `cstride` kwargs set the stride used to
1720-
sample the input data to generate the graph.
1720+
sample the input data to generate the graph. If either is 0
1721+
the input data in not sampled along this direction producing a
1722+
3D line plot rather than a wireframe plot.
17211723
17221724
========== ================================================
17231725
Argument Description
@@ -1748,14 +1750,23 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
17481750
# This transpose will make it easy to obtain the columns.
17491751
tX, tY, tZ = np.transpose(X), np.transpose(Y), np.transpose(Z)
17501752

1751-
rii = list(xrange(0, rows, rstride))
1752-
cii = list(xrange(0, cols, cstride))
1753+
if rstride:
1754+
rii = list(xrange(0, rows, rstride))
1755+
# Add the last index only if needed
1756+
if rows > 0 and rii[-1] != (rows - 1) :
1757+
rii += [rows-1]
1758+
else:
1759+
rii = []
1760+
if cstride:
1761+
cii = list(xrange(0, cols, cstride))
1762+
# Add the last index only if needed
1763+
if cols > 0 and cii[-1] != (cols - 1) :
1764+
cii += [cols-1]
1765+
else:
1766+
cii = []
17531767

1754-
# Add the last index only if needed
1755-
if rows > 0 and rii[-1] != (rows - 1) :
1756-
rii += [rows-1]
1757-
if cols > 0 and cii[-1] != (cols - 1) :
1758-
cii += [cols-1]
1768+
if rstride == 0 and cstride == 0:
1769+
raise ValueError("Either rstride or cstride must be non zero")
17591770

17601771
# If the inputs were empty, then just
17611772
# reset everything.
Loading
Loading

‎lib/mpl_toolkits/tests/test_mplot3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_mplot3d.py
+32-1Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import sys
2+
import nose
3+
from nose.tools import assert_raises
14
from mpl_toolkits.mplot3d import Axes3D, axes3d
25
from matplotlib import cm
3-
from matplotlib.testing.decorators import image_comparison
6+
from matplotlib.testing.decorators import image_comparison, cleanup
47
import matplotlib.pyplot as plt
58
import numpy as np
69

@@ -172,6 +175,34 @@ def test_wireframe3d():
172175
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
173176

174177

178+
@image_comparison(baseline_images=['wireframe3dzerocstride'], remove_text=True,
179+
extensions=['png'])
180+
def test_wireframe3dzerocstride():
181+
fig = plt.figure()
182+
ax = fig.add_subplot(111, projection='3d')
183+
X, Y, Z = axes3d.get_test_data(0.05)
184+
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=0)
185+
186+
187+
@image_comparison(baseline_images=['wireframe3dzerorstride'], remove_text=True,
188+
extensions=['png'])
189+
def test_wireframe3dzerorstride():
190+
fig = plt.figure()
191+
ax = fig.add_subplot(111, projection='3d')
192+
X, Y, Z = axes3d.get_test_data(0.05)
193+
ax.plot_wireframe(X, Y, Z, rstride=0, cstride=10)
194+
195+
@cleanup
196+
def test_wireframe3dzerostrideraises():
197+
if sys.version_info[:2] < (2, 7):
198+
raise nose.SkipTest("assert_raises as context manager "
199+
"not supported with Python < 2.7")
200+
fig = plt.figure()
201+
ax = fig.add_subplot(111, projection='3d')
202+
X, Y, Z = axes3d.get_test_data(0.05)
203+
with assert_raises(ValueError):
204+
ax.plot_wireframe(X, Y, Z, rstride=0, cstride=0)
205+
175206
@image_comparison(baseline_images=['quiver3d'], remove_text=True)
176207
def test_quiver3d():
177208
fig = plt.figure()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.