Gatto Nou
Gatto Nou

Reputation: 99

Matplotlib projection 3d levels issue

I've got quite strange error which comes from contourf(). I want to set specific min and max values for my 3D projection, however when I'm trying to set something bigger than -+max(Z) I get the error message:

File "C:\Program Files\Python38\lib\site-packages\mpl_toolkits\mplot3d\art3d.py", line 768, in do_3d_projection zzs, segments_2d, self._facecolors2d, self._edgecolors2d, idxs =
ValueError: not enough values to unpack (expected 5, got 0)

lmin,lmax = -1, 1 works only or lower values

Here is the example:

from pylab import *

mpName = 'seismic'

X = np.linspace(-np.pi, np.pi, 192)
Y = np.linspace(-np.pi, np.pi, 192)
X, Y = np.meshgrid(X, Y)
Z = np.sin(X*Y)


lmin,lmax = -2, 2 #
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.contourf(Y, X, Z, cmap='RdBu', zdir='z', offset=np.pi, levels=np.linspace(lmin,lmax,20))
ax.set_xlim3d(-np.pi, np.pi)
ax.set_ylim3d(-np.pi, np.pi)
ax.set_zlim3d(-np.pi, np.pi)
plt.show()

Upvotes: 5

Views: 404

Answers (1)

Gatto Nou
Gatto Nou

Reputation: 99

So, I found the solution to my problem.

conda remove --force matplotlib
conda install matplotlib=3.1.3

I don't know why, but the latest version produces the above mentioned error.

Upvotes: 2

Related Questions