您似乎想在basemap中生成一个choropleth图。
为此,您需要一个colormapcmap和一个规范化norm,以便将值映射到颜色,cmap(norm(val))。对于每个形状,可以将Polygon的颜色设置为字典中相应的颜色,在本例中是cmap(norm(dict1[info['ID_2']]))。在
在PatchCollection内,match_original=True需要设置以保持原始多边形的颜色。在
最后,从colormap和规范化生成一个colormap可能是有用的。在import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
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='w',lake_color='aqua')
m.drawcoastlines()
m.rea