【发布时间】:2018-01-30 11:32:35
【问题描述】:
我正在寻找基于值填充 shapefile 多边形的方法。 到目前为止,从底图教程 (http://basemaptutorial.readthedocs.io/en/latest/shapefile.html) 开始,我已经找到了如何用特定颜色填充多边形。
import matplotlib.pyplot as plt
import pypyodbc
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from matplotlib.patches import PathPatch
import numpy as np
fig= plt.figure()
ax= fig.add_subplot(111)
m=Basemap(projection='cyl',llcrnrlat=34.5,llcrnrlon=19,urcrnrlat=42,urcrnrlon=28.5,resolution='h')
m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='#ddaa66',lake_color='aqua')
m.drawcoastlines()
m.readshapefile('nomoi','nomoi')
patches = []
for info, shape in zip(m.nomoi_info, m.nomoi):
if info['ID_2'] == 14426:
patches.append( Polygon(np.array(shape), True) )
ax.add_collection(PatchCollection(patches, facecolor='m', edgecolor='k', linewidths=1., zorder=2))
plt.show()
我想做的是从这样的字典中获取值:
dict1={14464: 1.16, 14465: 1.35, 14466: 1.28, 14467: 1.69, 14468: 1.81, 14418: 1.38}
其中键是 shapefile 中的 info['ID_2'] 列,如上面的代码所示,值是我要表示颜色的变量。意味着有一个从 1.16 到 1.81 变化的颜色图,并且每个多边形 (ID_2) 都有一个与其来自 dict1 的值相关的颜色。
提前致谢
【问题讨论】:
-
从哪里获得 nomoi shapefile?
-
我不知道在哪里上传我希望这能工作drive.google.com/open?id=1Q47l1uSomLyDrHG2mxMiK3solsmWwcOd
标签: python matplotlib shapefile matplotlib-basemap