有没有办法使用matplotlib.patches.Wedge的半径以公里为单位而不是度数?

问题描述

我目前想在cartopy中绘制一个类似扇形的楔形,所以我查找了matplotlib.patches.Wedge方法。这几乎是我需要的功能,但是它需要的参数radius的单位是,而不是公里。 是否可以在公里中使用matplotlib.patches.Wedge方法而不是

谢谢。

my idea image here

解决方法

我假设您说“而不是度”表示您正在使用lon / lat的职位。最简单的方法是将lon / lat中心点转换为地图上的位置。在绘制时,我们实际上还将使用以米为单位的半径:

import matplotlib.pyplot as plt
from matplotlib.patches import Wedge
import cartopy.crs as ccrs

proj = ccrs.LambertConformal()
latlon_proj = ccrs.PlateCarree()
lat = 18
lon = 140
radius = 500  # In km
x,y = proj.transform_point(lon,lat,src_crs=latlon_proj)

fig = plt.figure()
ax = fig.add_subplot(1,1,projection=proj)
ax.plot(x,y,'ro')
# Here we need to convert radius to meters
ax.add_patch(Wedge((x,y),r=radius * 1000,theta1=0,theta2=90))
ax.coastlines()