首页 > 解决方案 > 底图 m.scatter 不允许点出现在地图上并保留填充大陆颜色

问题描述

我有这个 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=0fillcontinents它们确实会出现,但整个地图都是aqua彩色的。如果我没有zorder=0并且我使用m.plot而不是m.scatter绘制点,但它们之间会出现我不想要的线条。

如何让点自行出现但保留fillcontinents颜色?

可能的解决方案

我添加zorder=2m.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()

标签: pythonpython-3.xmatplotlibmatplotlib-basemap

解决方案


我添加zorder=2m.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()

推荐阅读