8000 Merge pull request #5166 from Tillsten/fix_#3116 · matplotlib/matplotlib@5511061 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5511061

Browse files
committed
Merge pull request #5166 from Tillsten/fix_#3116
FIX: Don't allow 1d-arrays in plot_surface.
2 parents d063dee + 85604a0 commit 5511061

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,8 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
15811581

15821582
had_data = self.has_data()
15831583

1584-
Z = np.atleast_2d(Z)
1584+
if Z.ndim != 2:
1585+
raise ValueError("Argument Z must be 2-dimensional.")
15851586
# TODO: Support masked arrays
15861587
X, Y, Z = np.broadcast_arrays(X, Y, Z)
15871588
rows, cols = Z.shape
@@ -1755,7 +1756,8 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
17551756
cstride = kwargs.pop("cstride", 1)
17561757

17571758
had_data = self.has_data()
1758-
Z = np.atleast_2d(Z)
1759+
if Z.ndim != 2:
1760+
raise ValueError("Argument Z must be 2-dimensional.")
17591761
# FIXME: Support masked arrays
17601762
X, Y, Z = np.broadcast_arrays(X, Y, Z)
17611763
rows, cols = Z.shape

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,17 @@ def test_axes3d_cla():
311311
ax.set_axis_off()
312312
ax.cla() # make sure the axis displayed is 3D (not 2D)
313313

314-
314+
@cleanup
315+
def test_plotsurface_1d_raises():
316+
x = np.linspace(0.5, 10, num=100)
317+
y = np.linspace(0.5, 10, num=100)
318+
X, Y = np.meshgrid(x, y)
319+
z = np.random.randn(100)
320+
321+
fig = plt.figure(figsize=(14,6))
322+
ax = fig.add_subplot(1, 2, 1, projection='3d')
323+
assert_raises(ValueError, ax.plot_surface, X, Y, z)
324+
315325
if __name__ == '__main__':
316326
import nose
317327
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)
0