Closed
Description
Bug summary
Calling ax.contour(x, y, z)
fails if ax
was created with projection="3d"
and x
and y
are both 1d
and different lengths.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
NX = 30
NY = 20
x = np.linspace(-10, 10, NX)
y = np.linspace(-10, 10, NY)
z = np.random.randint(0, 2, [NY, NX])
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.contour(x, y, z, [0.5], zdir="z")
plt.show()
Actual outcome
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.py", line 12, in <module>
ax.contour(x, y, z, [0.5], zdir="z")
File "/usr/lib/python3.8/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 2076, in contour
self.auto_scale_xyz(X, Y, Z, had_data)
File "/usr/lib/python3.8/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 650, in auto_scale_xyz
np.column_stack([X, Y]), not had_data)
File "<__array_function__ internals>", line 5, in column_stack
File "/usr/lib/python3.8/site-packages/numpy/lib/shape_base.py", line 656, in column_stack
return _nx.concatenate(arrays, 1)
File "<__array_function__ internals>", line 5, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 30 and the array at index 1 has size 20
If I call plt.pause(1)
after the traceback, a plot shows up showing the plot with x and y limits [0, 1], which doesn't show much that is comprehensible. If I call ax.set_xlim(-10, 10)
and ax.set_ylim(-10, 10)
, the plot shows up fine.
Expected outcome
Changing NX
to 20 produces a 3d plot with a set of contours hovering around z=0.5
Operating system
Cygwin, Windows
Matplotlib Version
3.3.3, 3.4.3
Matplotlib Backend
TkAgg, matplotlib_inline.backend_inline
Python version
3.8.10; 3.9.7
Jupyter version
No response
Other libraries
matplotlib_inline==0.1.3
Installation
conda
Conda channel
conda-forge