-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgeomap.py
154 lines (130 loc) · 6.3 KB
/
geomap.py
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import pandas as pd
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, AutoMinorLocator)
from matplotlib.gridspec import GridSpec
shapefile = 'bokeh-app/data/countries_110m/ne_110m_admin_0_countries.shp'
#Read shapefile using Geopandas
gdf = gpd.read_file(shapefile)[['ADMIN', 'ADM0_A3', 'geometry']]
#Rename columns.
gdf.columns = ['country', 'country_code', 'geometry']
gdf = gdf.drop(gdf.index[159]) #地图宽度
# #Drop row corresponding to 'Antarctica'
# datafile = 'bokeh-app/data/Countries of the world.csv'
datafile = 'bokeh-app/data/country-plot.csv'
data=pd.read_csv(datafile,usecols=[0,1],names=['country','Volume (Sum)(%)'])#导入数据
# data['Volume (Sum)(%)'] = data['Volume (Sum)(%)']/(73.3024)
print(data['Volume (Sum)(%)'])
#Read data to json.
data = gpd.GeoDataFrame(data)
merged = gdf.merge(data,on = 'country',how='left')
#low -> high
colorslist = ['#E3E3E1','#DFDCC6','#585332']
mycmaps = colors.LinearSegmentedColormap.from_list('mylist',colorslist,N=800)
fig,ax = plt.subplots(figsize = (10,6))
merged.plot(
column = 'Volume (Sum)(%)',
scheme = 'userdefined',
classification_kwds = {'bins':[0,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05,0.1,0.2,0.3,0.4]},
cmap = mycmaps,
edgecolor = 'black',
linewidth = 0.1,
ax = ax,
)
# albers_proj = '+proj=aea +lat_1=25 +lat_2=47 +lon_0=105'
# ax = data.to_crs(albers_proj).plot(ax=ax,
# missing_kwds={
# "color": "lightgrey",
# "edgecolor": "black",
# "hatch": "////"
# },
# legend=True,
# scheme='NaturalBreaks',
# k=5)
plt.xlim(-182,182)
plt.ylim(-58,86)
plt.axis('off') # 去坐标轴
plt.text(-169,-3.2,'High',family = 'Times New Roman',fontsize = 7)
# plt.text(-169,-30.2,r'$20\%$',family = 'Times New Roman',fontsize = 8)
plt.text(-169,-57.2,'Low',family = 'Times New Roman',fontsize = 7)
plt.text(-174.3,-1.9,r'$-$',family = 'Times New Roman',fontsize = 6,color = 'grey')
# plt.text(-174.3,-29.22,r'$-$',family = 'Times New Roman',fontsize = 6,color = 'grey')
plt.text(-174.3,-56.54,r'$-$',family = 'Times New Roman',fontsize = 6,color = 'grey')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
sm = plt.cm.ScalarMappable(cmap=mycmaps)
position=fig.add_axes([0.131, 0.24, 0.015, 0.2005])#位置[左,下,右,上]
cb=plt.colorbar(sm,cax=position,orientation='vertical',drawedges=False)#方向
cb.outline.set_visible(False)
cb.set_ticks([]) # 去x坐标刻度
plt.savefig('picture/result_mycmaps_dpi=150.jpg', bbox_inches='tight', pad_inches = 0,dpi=150)
plt.savefig('picture/result_mycmaps_dpi=150.png', bbox_inches='tight', pad_inches = 0,dpi=150)
plt.savefig('picture/result_mycmaps_dpi=150.tiff', bbox_inches='tight', pad_inches = 0,dpi=150)
fig,ax = plt.subplots(figsize = (10,6))
merged.plot(
column = 'Volume (Sum)(%)',
scheme = 'userdefined',
classification_kwds =
# {'bins':[0,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05,0.1,0.2,0.3,0.4]},#字典型,传入与分层设色相关的个性化参数
{'bins':[0,0.005,0.01,0.05,0.1,0.5,1,5,10,50,100,200,300,400]},
cmap = mycmaps,
edgecolor = 'black',
linewidth = 0.1,
ax = ax,
)
plt.xlim(-182,182)
plt.ylim(-58,86)
plt.axis('off') # 去坐标轴
plt.text(-169,-3.2,'High',family = 'Times New Roman',fontsize = 7)
# plt.text(-169,-30.2,r'$20\%$',family = 'Times New Roman',fontsize = 8)
plt.text(-169,-57.2,'Low',family = 'Times New Roman',fontsize = 7)
plt.text(-174.3,-1.9,r'$-$',family = 'Times New Roman',fontsize = 6,color = 'grey')
# plt.text(-174.3,-29.22,r'$-$',family = 'Times New Roman',fontsize = 6,color = 'grey')
plt.text(-174.3,-56.54,r'$-$',family = 'Times New Roman',fontsize = 6,color = 'grey')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
sm = plt.cm.ScalarMappable(cmap=mycmaps)
position=fig.add_axes([0.131, 0.24, 0.015, 0.2005])#位置[左,下,右,上]
cb=plt.colorbar(sm,cax=position,orientation='vertical',drawedges=False)#方向
cb.outline.set_visible(False)
cb.set_ticks([])
plt.savefig('picture/result_mycmaps_dpi=300.jpg', bbox_inches='tight',pad_inches = 0,dpi=300)
plt.savefig('picture/result_mycmaps_dpi=300.png', bbox_inches='tight', pad_inches = 0,dpi=300)
plt.savefig('picture/result_mycmaps_dpi=300.tiff', bbox_inches='tight', pad_inches = 0,dpi=300)
fig,ax = plt.subplots(figsize = (10,6))
#
merged.plot(
column = 'Volume (Sum)(%)',
scheme = 'userdefined',
classification_kwds = {'bins':[0,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05,0.1,0.2,0.3,0.4]},
cmap = mycmaps,
edgecolor = 'black',
linewidth = 0.1,
ax = ax,
)
plt.xlim(-182,182)
plt.ylim(-58,86)
plt.axis('off') # 去坐标轴
plt.text(-169,-3.2,'High',family = 'Times New Roman',fontsize = 7)
# plt.text(-169,-30.2,r'$20\%$',family = 'Times New Roman',fontsize = 8)
plt.text(-169,-57.2,'Low',family = 'Times New Roman',fontsize = 7)
plt.text(-174.3,-1.9,r'$-$',family = 'Times New Roman',fontsize = 6,color = 'grey')
# plt.text(-174.3,-29.22,r'$-$',family = 'Times New Roman',fontsize = 6,color = 'grey')
plt.text(-174.3,-56.54,r'$-$',family = 'Times New Roman',fontsize = 6,color = 'grey')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
sm = plt.cm.ScalarMappable(cmap=mycmaps)
position=fig.add_axes([0.131, 0.24, 0.015, 0.2005])#位置[左,下,右,上]
cb=plt.colorbar(sm,cax=position,orientation='vertical',drawedges=False)#方向
cb.outline.set_visible(False)
cb.set_ticks([])
plt.savefig('picture/result_mycmaps_dpi=150.svg', bbox_inches='tight', pad_inches = 0,dpi=150)
plt.savefig('picture/result_mycmaps_dpi=300.svg', bbox_inches='tight', pad_inches = 0,dpi=300)