matplotlib / cartopy-切断颤动键

问题描述

注意:移至matplotlib quiver key label getting cut

一个较小示例

尝试工作,因为当前已切断,所以如何在图中保留颤音键。我使用的是cartopy,希望将箭键放在地图外。这是目前的样子。我已突出显示了颤动键的显示位置,但向东的文本会被自动截断。下面给出的代码取自docs

enter image description here

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()

解决方法

我对此没有经验,但是x的位置很重要,因为更改put.quiverkey()中x的位置会导致显示字符串。 labelpos='W'会在西边显示它。

qk = plt.quiverkey(q,0.9,0.92,30,'velocity (30 m s$^{-1}$)',labelpos='W',transform=ccrs.PlateCarree(),color='r')

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...