5

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()
Gatto Nou
  • 89
  • 1
  • 12
  • Unrelated to your problem: [Why is import * bad](https://stackoverflow.com/questions/2386714/why-is-import-bad) and [pylab is deprecated and its use is strongly discouraged because of namespace pollution. Use pyplot instead.](https://matplotlib.org/3.1.1/tutorials/introductory/usage.html) – Mr. T Dec 03 '20 at 18:35
  • Does this answer your question? [Problems With Contours Using Python's matplotlib 3D API](https://stackoverflow.com/questions/64236239/problems-with-contours-using-pythons-matplotlib-3d-api) – Mr. T Dec 03 '20 at 19:04
  • Mr. T thanks for your suggestions but that case doesn't solve my question. I have problem with setting levels to contourf. – Gatto Nou Dec 04 '20 at 00:23
  • Could you specify more clearly what exactly you want to achieve? You want a 2D projection of your data but leave out some of the z values? Why would you like to set the min and max contour levels outside of your data range? – BenB Dec 04 '20 at 22:16
  • Good question. I need this because I have 3 data sets and they have different min/max values. I'm plotting 3D figure which consists of 3 projections. In order to be consistent with levels I should use same values of min/max for each data set. – Gatto Nou Dec 06 '20 at 10:05

1 Answers1

2

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.

Gatto Nou
  • 89
  • 1
  • 12