单箭头箭袋图似乎不适用于 cartopy PlateCarree 变换

Single-arrow quiver plots don't seem to work with the cartopy PlateCarree transform

我试图在地图上使用 plt.quiver 一次创建单个箭头(即仅在一个位置显示风矢量)。但是,在这样做时使用(通过使用 ccrs.PlateCarree() 转换)我遇到一个问题,其中某些子函数试图获取 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())

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

我正在使用 cartopy 0.18.0 和 matplotlib 3.2.1。

提前感谢您的任何建议!

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

调用签名:

quiver([X, Y], U, V, [C], **kw)

  • X, Y: 1D or 2D array-like

如果X,Y,U,V的所有数都放入数组形式:

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

它会起作用。