1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123我是准备给14个地区染色,但是能成功上色的只有6个省和直辖市。
请问这是Basemap画地图的bug吗?
代码如下:
plt.figure(figsize=(16,10))
map = Basemap(llcrnrlon=77, llcrnrlat=14, urcrnrlon=140, urcrnrlat=51,projection='lcc',lat_1=33, lat_2=45, lon_0=100)
map.drawcoastlines()
map.readshapefile('CHN_adm1', 'states', drawbounds=True)
#map.drawcountries()
statenames=[]
for shapedict in map.states_info:
statename = shapedict['NL_NAME_1']
p = statename.split('|')
if len(p) > 1:
s = p[1]
else:
s = p[0]
statenames.append(s)
ax = plt.gca()
seg = map.states[statenames.index('四川')]
seg1 = map.states[statenames.index('湖南')]
seg2 = map.states[statenames.index('江苏')]
seg3 = map.states[statenames.index('上海')]
seg4 = map.states[statenames.index('安徽')]
seg5 = map.states[statenames.index('浙江')]
seg6 = map.states[statenames.index('北京')]
seg7 = map.states[statenames.index('山东')]
seg8 = map.states[statenames.index('江西')]
seg9 = map.states[statenames.index('广西')]
seg10 = map.states[statenames.index('湖北')]
poly = Polygon(seg,facecolor = 'crimson',edgecolor = 'r')
poly1 = Polygon(seg1,facecolor = 'crimson',edgecolor = 'r')
poly2 = Polygon(seg2,facecolor = 'crimson',edgecolor = 'r')
poly3 = Polygon(seg3,facecolor = 'violet',edgecolor = 'r')
poly4 = Polygon(seg4,facecolor = 'violet',edgecolor = 'r')
poly5 = Polygon(seg5,facecolor = 'violet',edgecolor = 'r')
poly6 = Polygon(seg6,facecolor = 'gold',edgecolor = 'r')
poly7 = Polygon(seg7,facecolor = 'gold',edgecolor = 'r')
poly8 = Polygon(seg8,facecolor = 'coral',edgecolor = 'r')
poly9 = Polygon(seg9,facecolor = 'coral',edgecolor = 'r')
poly10 = Polygon(seg10,facecolor = 'coral',edgecolor = 'r')
ax.add_patch(poly)
ax.add_patch(poly1)
ax.add_patch(poly2)
ax.add_patch(poly3)
ax.add_patch(poly4)
ax.add_patch(poly5)
ax.add_patch(poly6)
ax.add_patch(poly7)
ax.add_patch(poly8)
ax.add_patch(poly9)
ax.add_patch(poly10)
plt.show()