/
nerv_style.py
100 lines (89 loc) · 2.06 KB
/
nerv_style.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
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import opencc
import frykit.plot as fplt
import frykit.shp as fshp
# 线条颜色
linecolor = '#a3ffc2'
boxcolor = '#f29305'
fontcolor = '#ffc292'
# 繁体化省名
converter = opencc.OpenCC('s2t.json')
table = fshp.get_cn_province_table()
names = table['short_name'].tolist()
for i, name in enumerate(names):
if name == '香港' or name == '澳门':
name = ''
names[i] = converter.convert(name)
# 设置投影
map_crs = fplt.CN_AZIMUTHAL_EQUIDISTANT
data_crs = ccrs.PlateCarree()
# 创建画布
fig = plt.figure(facecolor='k')
ax = fig.add_subplot(111, projection=map_crs)
ax.set_extent([76, 134, 2, 55], crs=data_crs)
ax.set_facecolor('k')
ax.axis('off')
# 绘制省界和市界
fplt.add_cn_province(ax, lw=0.6, ec=linecolor)
fplt.add_cn_city(ax, lw=0.2, ec=linecolor)
fplt.add_nine_line(ax, lw=0.6, ec=linecolor)
# 两种风格的方框
hollow_props = {
'boxstyle': 'round, rounding_size=0.2',
'fc': 'none',
'ec': boxcolor,
'lw': 1,
'alpha': 0.8,
}
solid_props = {
'boxstyle': 'round, rounding_size=0.2',
'fc': boxcolor,
'ec': 'none',
'alpha': 0.8,
}
# 添加说明框
ax.text(
x=0.2,
y=0.2,
s='CHINA MAP',
color=boxcolor,
alpha=hollow_props['alpha'],
fontsize=10,
fontfamily='Helvetica Neue',
fontweight='bold',
ha='left',
va='center',
bbox=hollow_props,
transform=ax.transAxes,
)
ax.text(
x=0.2,
y=0.26,
s='SEP 2022',
color=boxcolor,
alpha=hollow_props['alpha'],
fontsize=10,
fontfamily='Helvetica Neue',
fontweight='bold',
ha='left',
va='center',
transform=ax.transAxes,
)
# 添加省名
for name, lon, lat in zip(names, table['lon'], table['lat']):
ax.text(
x=lon,
y=lat,
s=name,
color=fontcolor,
fontsize=4,
fontfamily='FOT-Matisse Pro',
ha='center',
va='center',
bbox=solid_props,
transform=data_crs,
)
# 保存图片
fig.savefig('../image/nerv_style.png', dpi=300, bbox_inches='tight')
plt.close(fig)