【问题标题】:How can I plot function values on a sphere?如何在球体上绘制函数值?
【发布时间】:2015-11-17 22:54:47
【问题描述】:

我有一个 Nx2 的经纬度坐标对矩阵 spatial_data,并且我在这些坐标上有一组测量值。

我想在地球仪上绘制这些数据,并且我知道 Basemap 可以做到这一点。我找到了this 链接,它显示了如果您有笛卡尔坐标,如何绘制数据。是否存在将纬度、经度转换为笛卡尔坐标的功能?或者,有没有办法仅使用 lat,lon 信息来绘制这些数据?

【问题讨论】:

    标签: numpy matplotlib matplotlib-basemap geopy


    【解决方案1】:

    你可以使用cartopy:

    import numpy as np
    import matplotlib.pyplot as plt
    from cartopy import crs
    
    # a grid for the longitudes and latitudes
    lats = np.linspace(-90, 90, 50)
    longs = np.linspace(-180, 180, 50)
    lats, longs = np.meshgrid(lats, longs)
    
    # some data
    data = lats[1:] ** 2 + longs[1:] ** 2
    
    fig = plt.figure()
    
    # create a new axes with a cartopy.crs projection instance
    ax = fig.add_subplot(1, 1, 1, projection=crs.Mollweide())
    
    # plot the date
    ax.pcolormesh(
        longs, lats, data,
        cmap='hot',
        transform=crs.PlateCarree(),  # this means that x, y are given as longitude and latitude in degrees
    )
    fig.tight_layout()
    fig.savefig('cartopy.png', dpi=300)
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-11
      • 2010-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多