如何用python画出中国地图-如何让使用python绘制中国地图并给特定地区上色?

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()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值