【问题标题】:scatter plot data does not appear on continents in 'hammer' basemap散点图数据不会出现在“锤子”底图中的大陆上
【发布时间】:2015-06-17 21:07:49
【问题描述】:

我正在尝试使用散点图在“锤子”底图上绘制数据集。但是,数据点不会绘制在各大洲之上。我注意到在 matplotlib example 中,也没有大陆上的数据(我认为这是由于示例的性质)。我想知道我是否做错了什么,或者数据是否无法通过设计使用“锤子”绘制在大陆之上。

如果是这种情况,是否有理想的底图可用于绘制整个地球上的散点图数据(使用地形图会很棒,但此时我会满足于任何东西)?

【问题讨论】:

    标签: python matplotlib scatter matplotlib-basemap


    【解决方案1】:

    您可能缺少解释经纬度数据的关键字。来自 Basemap.scatter 的帮助:

    如果 latlon 关键字设置为 True,x,y 将被解释为经度 和以度为单位的纬度。数据和经度是自动的 移动以匹配圆柱形的地图投影区域和 伪圆柱投影,并将 x,y 转换为映射 投影坐标。如果latlon 为 False(默认),则 x 和 y 为 假定为地图投影坐标。

    我还需要增加 z 顺序以分散在大陆和海洋的顶部。

    import time, calendar, datetime, numpy
    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    # draw map with markers for float locations
    m = Basemap(projection='hammer',lon_0=180)
    m.drawmapboundary(fill_color='#99ffff')
    m.fillcontinents(color='#cc9966',lake_color='#99ffff')
    
    m.scatter([-73.98, 238., 0.08, 0., 116.38],[40.78,47.6,  51.53,0., 39.91],
              latlon=True, # Ta-da!
              marker='o',color='k',
              zorder=10)
    
    plt.title('Hammer projection, data on top',fontsize=12)
    plt.show()
    

    【讨论】:

    • 这太好了,谢谢!我已经使用 x, y = m(lons,lats) 设置了 latlon 数据。我缺少的是 zorder=10。不过,很高兴知道我可以在 scatter 中使用 latlon=True
    • 我很幸运,我选择了一个沿海城市作为测试用例,我可以看到 一半 标记 - 很明显它在大陆下面而不是海洋.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-02
    • 2017-12-18
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    相关资源
    最近更新 更多