【问题标题】:Lack of Projection for Cartopy ContourCartopy 轮廓缺乏投影
【发布时间】:2019-11-07 17:31:55
【问题描述】:

我正在尝试通过 cartopy 将一些数据放到等高线图上。但是,在绘制数据之后,投影似乎仍然关闭。 surface_temp.X 和 surface_temp.Y 是纬度/经度,而 masked_fill 是实际数据值。这似乎在底图中有效,但我不确定为什么它在 cartopy 中无效。

卡托比:

fig = plt.figure(figsize=(12,4.76), dpi=100)
fig.clf()
ax = plt.axes(projection=ccrs.Mercator())
ax.coastlines()
ax.contourf(surface_temp.X, surface_temp.Y, surface_temp.masked_fill[:], latlon = 'true', transform = ccrs.Mercator())
plt.show()

底图:

fig = plt.figure(figsize=(15,4.76), dpi=100)
        fig.clf()
        plt.axes([0,0,1,1], frameon=False)
        plt.title(title)
        m = Basemap(projection='merc',llcrnrlat=-80,urcrnrlat=80, llcrnrlon=0,urcrnrlon=360,lat_ts=20,resolution='c')
m.contourf(surface_temp.X, surface_temp.Y, surface_temp.masked_fill[:], latlon = 'true')

底图结果:

Cartopy 结果(轮廓注释掉):

Cartopoy 结果(轮廓)

【问题讨论】:

    标签: python matplotlib matplotlib-basemap cartopy


    【解决方案1】:

    cartopy seems to be 始终在纬度/经度坐标上工作的范例。这意味着,您不应根据投影转换数据,而应保持纬度/经度。

    因此,而不是

    ax.contourf(..., transform = ccrs.Mercator())
    

    你需要

    ax.contourf(..., transform = ccrs.PlateCarree())
    

    一个完整的例子:

    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    from cartopy.examples.waves import sample_data
    
    ax = plt.axes(projection=ccrs.Mercator())
    
    lons, lats, data = sample_data(shape=(20, 40))
    
    ax.contourf(lons, lats, data, transform=ccrs.PlateCarree())
    
    ax.coastlines()
    ax.gridlines()
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 2017-02-17
      • 2021-02-25
      • 2011-09-04
      相关资源
      最近更新 更多