【问题标题】:is there a way to use matplotlib.patches.Wedge's radius in km instead of degrees?有没有办法使用 matplotlib.patches.Wedge 的半径而不是度数?
【发布时间】:2020-12-20 02:33:17
【问题描述】:

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

谢谢。

my idea image here

【问题讨论】:

    标签: matplotlib matplotlib-basemap cartopy


    【解决方案1】:

    我假设您说“而不是度数”意味着您正在处理经度/纬度的职位。最简单的方法是将您的经度/纬度中心点转换为地图上的位置。我们实际上也会在绘图时使用以米为单位的半径:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-27
      • 1970-01-01
      • 2014-06-07
      • 2022-11-22
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 2017-09-13
      相关资源
      最近更新 更多