问题描述
注意:移至matplotlib quiver key label getting cut
的一个较小示例尝试工作,因为当前已切断,所以如何在图中保留颤音键。我使用的是cartopy,希望将箭键放在地图外。这是目前的样子。我已突出显示了颤动键的显示位置,但向东的文本会被自动截断。下面给出的代码取自docs。
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
def sample_data(shape=(20,30)):
crs = ccrs.northPolarstereo()
scale = 1e7
x = np.linspace(-scale,scale,shape[1])
y = np.linspace(-scale,shape[0])
x2d,y2d = np.meshgrid(x,y)
u = 10 * np.cos(2 * x2d / scale + 3 * y2d / scale)
v = 20 * np.cos(6 * x2d / scale)
return x,y,u,v,crs
x,vector_crs = sample_data(shape=(50,50))
fig,ax = plt.subplots(1,1,figsize=(13,8))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines('50m')
ax.set_extent([-45,55,20,80],ccrs.PlateCarree())
q = ax.quiver(x,transform=vector_crs,regrid_shape=20)
qk = plt.quiverkey(q,0.9,30,'veLocity (30 m s$^{-1}$)',labelpos='E',transform=ccrs.PlateCarree())
plt.show()