matplotlib/底图的无河流世界地图? [英] world map without rivers with matplotlib / Basemap?

查看:219
本文介绍了matplotlib/底图的无河流世界地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使用底图(如果没有其他方法,也可以不使用底图)来绘制各大洲的边界,而不会出现那些烦人的河流呢?尤其是那条甚至没有到达海洋的金戈河,都令人不安.

Would there be a way to plot the borders of the continents with Basemap (or without Basemap, if there is some other way), without those annoying rivers coming along? Especially that piece of Kongo River, not even reaching the ocean, is disturbing.

我打算在地图上进一步绘制数据,例如底图图库(并且仍然有大陆的边界线在数据上绘制为黑线,以提供世界地图的结构),因此,尽管下面的Hooked解决方案很好,很精巧,但不适用于此目的.

I intend to further plot data over the map, like in the Basemap gallery (and still have the borderlines of the continents drawn as black lines over the data, to give structure for the worldmap) so while the solution by Hooked below is nice, masterful even, it's not applicable for this purpose.

图片产生者:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(8, 4.5))
plt.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.00)
m = Basemap(projection='robin',lon_0=0,resolution='c')
m.fillcontinents(color='gray',lake_color='white')
m.drawcoastlines()
plt.savefig('world.png',dpi=75)

推荐答案

按照user1868739的示例,我只能选择想要的路径(对于某些湖泊):

Following user1868739's example, I am able to select only the paths (for some lakes) that I want:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(8, 4.5))
plt.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.00)
m = Basemap(resolution='c',projection='robin',lon_0=0)
m.fillcontinents(color='white',lake_color='white',zorder=2)
coasts = m.drawcoastlines(zorder=1,color='white',linewidth=0)
coasts_paths = coasts.get_paths()

ipolygons = range(83) + [84] # want Baikal, but not Tanganyika
# 80 = Superior+Michigan+Huron, 81 = Victoria, 82 = Aral, 83 = Tanganyika,
# 84 = Baikal, 85 = Great Bear, 86 = Great Slave, 87 = Nyasa, 88 = Erie
# 89 = Winnipeg, 90 = Ontario
for ipoly in ipolygons:
    r = coasts_paths[ipoly]
    # Convert into lon/lat vertices
    polygon_vertices = [(vertex[0],vertex[1]) for (vertex,code) in
                        r.iter_segments(simplify=False)]
    px = [polygon_vertices[i][0] for i in xrange(len(polygon_vertices))]
    py = [polygon_vertices[i][2] for i in xrange(len(polygon_vertices))]
    m.plot(px,py,linewidth=0.5,zorder=3,color='black')

plt.savefig('world2.png',dpi=100)

但这仅在将白色背景用于各大洲时才有效.如果在下一行中将color更改为'gray',我们会看到其他河流和湖泊填充的颜色与各大洲的颜色不同. (也玩area_thresh不会删除那些与海洋相连的河流.)

But this only works when using white background for the continents. If I change color to 'gray' in the following line, we see that other rivers and lakes are not filled with the same color as the continents are. (Also playing with area_thresh will not remove those rivers that are connected to ocean.)

m.fillcontinents(color='gray',lake_color='white',zorder=2)

带有白色背景的版本足以对各大洲的各种土地信息进行彩色绘图,但是,如果要保留各大洲的灰色背景,则需要更精细的解决方案.

The version with white background is adequate for further color-plotting all kind of land information over the continents, but a more elaborate solution would be needed, if one wants to retain the gray background for continents.

这篇关于matplotlib/底图的无河流世界地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆