单箭头箭袋图似乎不适用于卡托普 PlateCarree 变换



我试图在地图上使用plt.箭袋一次创建单个箭头(即只显示一个位置的风矢量(。然而,在这样做的时候(通过使用ccrs.PlateCaree((转换(,我遇到了一个问题,其中一些子函数试图获得0-dim数组/int.的dims数量

以下是一些最小的工作示例:

from matplotlib import pyplot as plt
import cartopy 
import cartopy.crs as ccrs
%matplotlib inline
#### Works: simple quiver plot
plt.quiver(0,0,1,-1)

#### Works: simple quiver plot on a map axis, without specifying transform (this obviously would get the location wrong, but just to show what works/doesn't)
plt.subplot(projection=ccrs.EckertIV())
plt.quiver(0,0,1,-1)
#### Works: simple quiver plot on a map axis with some other transform
plt.subplot(projection=ccrs.EckertIV())
plt.quiver(0,0,1,-1,transform=ccrs.EckertIV())
#### Doesn't work: simple quiver plot on a map axis with the PlateCarree transform
plt.subplot(projection=ccrs.EckertIV())
plt.quiver(0,0,1,-1,transform=ccrs.PlateCarree())

最后一次调用会产生以下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-93-dec36b09994d> in <module>
1 plt.subplot(projection=ccrs.EckertIV())
----> 2 plt.quiver(0,0,1,-1,transform=ccrs.PlateCarree())
~/.conda/envs/climate1/lib/python3.7/site-packages/matplotlib/pyplot.py in quiver(data, *args, **kw)
2791 def quiver(*args, data=None, **kw):
2792     __ret = gca().quiver(
-> 2793         *args, **({"data": data} if data is not None else {}), **kw)
2794     sci(__ret)
2795     return __ret
~/.conda/envs/climate1/lib/python3.7/site-packages/cartopy/mpl/geoaxes.py in wrapper(self, *args, **kwargs)
308 
309         kwargs['transform'] = transform
--> 310         return func(self, *args, **kwargs)
311     return wrapper
312 
~/.conda/envs/climate1/lib/python3.7/site-packages/cartopy/mpl/geoaxes.py in quiver(self, x, y, u, v, *args, **kwargs)
1837             # Transform the vectors if the projection is not the same as the
1838             # data transform.
-> 1839             if (x.ndim == 1 and y.ndim == 1) and (x.shape != u.shape):
1840                 x, y = np.meshgrid(x, y)
1841             u, v = self.projection.transform_vectors(t, x, y, u, v)
AttributeError: 'int' object has no attribute 'ndim'

现在的一个变通方法是在同一个箭头上画两次,例如

plt.subplot(projection=ccrs.EckertIV())
plt.quiver(np.array([0,0]),np.array([0,0]),np.array([1,1]),np.array([-1,-1]),transform=ccrs.PlateCarree())

但我想知道我是否错过了让它正常工作的一些东西。

我使用的是caropy 0.18.0和matplotlib 3.2.1。

提前感谢您的建议!

有时必须严格遵守调用签名。

呼叫签名:

颤动([X],Y],U,V,[C],**kw(

  • X,Y:1D或2D类似阵列

如果X、Y、U、V的所有数字都以数组形式表示:

plt.quiver(np.array([0]),np.array([0]), 
np.array([1]),np.array([-1]), transform=ccrs.PlateCarree())

它会起作用的。

最新更新