【问题标题】:Basemap m.scatter not allowing points to appear on map and retain fillcontinents color底图 m.scatter 不允许点出现在地图上并保留填充大陆颜色
【发布时间】:2020-05-01 23:01:11
【问题描述】:

我有这个 Python 代码:

m = Basemap(projection='tmerc',
            llcrnrlon=-10.56,
            llcrnrlat=51.39,
            urcrnrlon=-5.34,
            urcrnrlat=55.43,
            resolution='h',
            epsg=29902)

# Fill the globe with blue color
m.drawmapboundary(fill_color='aqua')

# Draw country boundaries
m.drawcountries()

# Fill the continents with the land color
m.fillcontinents(color='coral', lake_color='aqua')

m.drawcoastlines()

lons = [-7.637558, -5.926437, -6.266155]
lats = [54.350155, 54.607868, 53.350140]

x, y = m(lons, lats)

m.scatter(x, y, marker='D', color='m')

plt.show()

当我运行它时,这些点不会出现在我的地图上。如果我将zorder=0 添加到fillcontinents,它们确实会出现,但整个地图是aqua 颜色。如果我没有zorder=0 并且我使用m.plot 而不是m.scatter,那么会绘制点,但它们之间会出现我不想要的线。

如何让点自行显示但保留fillcontinents 颜色?

可能的解决方案

我将zorder=2 添加到m.scatter。这是最 Pythonic 的方式吗?

m = Basemap(projection='tmerc',
            llcrnrlon=-10.56,
            llcrnrlat=51.39,
            urcrnrlon=-5.34,
            urcrnrlat=55.43,
            resolution='h',
            epsg=29902)

# Fill the globe with blue color
m.drawmapboundary(fill_color='aqua')

# Draw country boundaries
m.drawcountries()

# Fill the continents with the land color
m.fillcontinents(color='coral', lake_color='aqua')

m.drawcoastlines()

lons = [-7.637558, -5.926437, -6.266155]
lats = [54.350155, 54.607868, 53.350140]

x, y = m(lons, lats)

m.scatter(x, y, marker='D', color='m', zorder=2)

plt.show()

【问题讨论】:

    标签: python python-3.x matplotlib matplotlib-basemap


    【解决方案1】:

    我将zorder=2 添加到m.scatter。这是最 Pythonic 的方式吗?

    m = Basemap(projection='tmerc',
                llcrnrlon=-10.56,
                llcrnrlat=51.39,
                urcrnrlon=-5.34,
                urcrnrlat=55.43,
                resolution='h',
                epsg=29902)
    
    # Fill the globe with blue color
    m.drawmapboundary(fill_color='aqua')
    
    # Draw country boundaries
    m.drawcountries()
    
    # Fill the continents with the land color
    m.fillcontinents(color='coral', lake_color='aqua')
    
    m.drawcoastlines()
    
    lons = [-7.637558, -5.926437, -6.266155]
    lats = [54.350155, 54.607868, 53.350140]
    
    x, y = m(lons, lats)
    
    m.scatter(x, y, marker='D', color='m', zorder=2)
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2022-11-11
      • 2015-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-26
      • 2023-03-28
      • 1970-01-01
      • 2014-04-27
      相关资源
      最近更新 更多