【发布时间】:2020-02-07 22:33:39
【问题描述】:
我正在尝试使用 geopandas 绘制每个国家/地区的 Mirai 僵尸网络感染热图。我有一个结构如下的地理数据框:
geometry Country_Code Infection_Rate
0 MULTIPOLYGON (((11108970.260 445285.130, 11108... IDN 0.01616
6 POLYGON ((3008931.293 3740791.337, 3007063.917... NaN nan
7 MULTIPOLYGON (((3009012.519 3740778.293, 30089... CYP 0.06845
8 MULTIPOLYGON (((6915098.813 3796247.587, 69170... IND 0.0076
从结构中可以清楚地看出,存在一些缺失值,因为某些国家/地区的感染率未知
我将热图绘制如下:
## Some plot settings
colors = 6
cmap = 'Blues'
figsize = (16, 10)
plotvar = 'Infection_Rate'
scheme = 'equalinterval'
title = 'Infection rate per country (%)'
lables = ['0', '1', '2', '3','4','5']
## Create the plot
ax = geoinfect.plot(plotvar, cmap=cmap, figsize=figsize, k = colors, scheme = scheme, legend=True)
ax.set_title(title, fontdict={'fontsize': 20}, loc='left')
ax.set_axis_off()
ax.set_xlim([-1.5e7, 1.7e7])
legend.set_bbox_to_anchor((.52, .4))
## Highlight missing values in grey
geoinfect[geoinfect.isna().any(axis=1)].plot(ax=ax, color='#D3D3D3')
这给了我以下结果:Heatmap
除了样式不好之外,我对这个情节的主要问题是图例的第一个标签是“nan-0.21”而不是“0-0.21”
我是否可以手动编辑图例,使第一个标签显示“0-0.21”?
请原谅这是一个明显的错误,我对编程很陌生:)
【问题讨论】:
标签: python pandas python-2.7 legend geopandas