Я пытаюсь использовать python для построения 3D-графика, используя код ниже. Кажется, нельзя изобразить (lon, lat, lev, value) четыре измерения на одной фигуре. значение представляет переменную Zano_Tave_QV
.
Заранее спасибо.
from netCDF4 import Dataset
import numpy as np
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
#%matplotlib inline
my_file = 'Downloads/Zano_Tave_QV.nc'
fh = Dataset(my_file, mode='r')
#print(fh.variables)
fig = plt.figure()
ax = fig.gca(projection='3d')
X = fh.variables['lat'][:]
Y = fh.variables['lon'][:]
Z = fh.variables['lev'][:]
#F = H.reshape(len(X),len(Y))
cset = ax.contourf(X, Y, Z, cmp=cm.coolwarm)
print(H)
ax.clabel(xset, fontsize=9, inline=1)
plt.show()
Файл Zano_Tave_QV.nc
находится по этой ссылке https://drive.google.com/open?id=1IOmOkkvv1qyx-y1FRS6FKAJLnTt7UZ1s:
Информация о трассировке
TypeErrorTraceback (most recent call last)
<ipython-input-3-fec6b75cf787> in <module>()
18
19 #F = H.reshape(len(X),len(Y))
---> 20 cset = ax.contourf(X, Y, Z, cmp=cm.coolwarm)
21 print(H)
22 ax.clabel(xset, fontsize=9, inline=1)
~/anaconda3/lib/python3.6/site-packages/mpl_toolkits/mplot3d/axes3d.py in contourf(self, X, Y, Z, *args, **kwargs)
2221
2222 jX, jY, jZ = art3d.rotate_axes(X, Y, Z, zdir)
-> 2223 cset = super(Axes3D, self).contourf(jX, jY, jZ, *args, **kwargs)
2224 self.add_contourf_set(cset, zdir, offset)
2225
~/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1853 "the Matplotlib list!)" % (label_namer, func.__name__),
1854 RuntimeWarning, stacklevel=2)
-> 1855 return func(ax, *args, **kwargs)
1856
1857 inner.__doc__ = _add_data_doc(inner.__doc__,
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in contourf(self, *args, **kwargs)
6179 self.cla()
6180 kwargs['filled'] = True
-> 6181 contours = mcontour.QuadContourSet(self, *args, **kwargs)
6182 self.autoscale_view()
6183 return contours
~/anaconda3/lib/python3.6/site-packages/matplotlib/contour.py in __init__(self, ax, *args, **kwargs)
844 self._transform = kwargs.pop('transform', None)
845
--> 846 kwargs = self._process_args(*args, **kwargs)
847 self._process_levels()
848
~/anaconda3/lib/python3.6/site-packages/matplotlib/contour.py in _process_args(self, *args, **kwargs)
1414 self._corner_mask = mpl.rcParams['contour.corner_mask']
1415
-> 1416 x, y, z = self._contour_args(args, kwargs)
1417
1418 _mask = ma.getmask(z)
~/anaconda3/lib/python3.6/site-packages/matplotlib/contour.py in _contour_args(self, args, kwargs)
1472 args = args[1:]
1473 elif Nargs <= 4:
-> 1474 x, y, z = self._check_xyz(args[:3], kwargs)
1475 args = args[3:]
1476 else:
~/anaconda3/lib/python3.6/site-packages/matplotlib/contour.py in _check_xyz(self, args, kwargs)
1506
1507 if z.ndim != 2:
-> 1508 raise TypeError("Input z must be a 2D array.")
1509 elif z.shape[0] < 2 or z.shape[1] < 2:
1510 raise TypeError("Input z must be at least a 2x2 array.")
TypeError: Input z must be a 2D array.