0

此代码来自 Basemap 文档页面,其中一些更改集中在我手头的问题上。我想为所有陆地(可以忽略南极洲)着色(在这种情况下为洋红色),并且所有海洋都应该像现在的南极洲一样是白色的。shapefile 来自这里在此处输入图像描述

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from matplotlib.patches import PathPatch
import numpy as np

fig = plt.figure(figsize=(20,20))
ax = fig.add_subplot(111)

map = Basemap(llcrnrlon=-180,llcrnrlat=-85,urcrnrlon=180.,urcrnrlat=85, projection='merc')

map.readshapefile('countries_lakes/ne_10m_admin_0_countries_lakes', 'units')

patches = []

for info, shape in zip(map.units_info, map.units):
    patches.append(Polygon(np.array(shape), True))

ax.add_collection(PatchCollection(patches, facecolor= 'm', edgecolor='k', linewidths=1.))

plt.savefig('dem.png', bbox_inches='tight')
4

0 回答 0