在我创建的 Geopandas 世界 Choropleth 中,我希望可以编辑颜色条的多个属性,包括大小(大约与地图本身匹配)、文本大小(当前显示得太小)以及添加标签。从一些阅读中得知,在 Geopandas 中没有简单的方法来明确地解决这个问题,所以我想知道是否有人能提供任何解决方案?非常感谢您的帮助。
以下是我目前正在使用的代码(为了一些背景信息,中间部分仅是将按国家汇总的列表与数字合并,作为着色的基础,并将其与框架合并)
fig, ax = plt.subplots(figsize=(40,29.171))
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world=pd.DataFrame(world)
world['LEADS']=0.1
world = world.set_index('name')
world['name']=world.index
for x, y in zip(Countries, country_counts):
world.loc[x, 'LEADS'] = y
world=geopandas.GeoDataFrame(world)
world = world[(world.index != "Antarctica")]
ax.set_axis_off()
#ax.legend(title="Leads")
world.plot(ax=ax, column='LEADS', cmap='Oranges', legend=True,linewidth = 1.5)
plt.tight_layout()
plt.savefig('plot_image.png', bbox_inches='tight', transparent=True)
在这里,一个理想的解决方案将保持图例选项具有的颜色,指定大小和文本大小,并在条形图顶部启用标签。不幸的是,我自己也很难弄清楚这些内容是如何完成的。
data.plot()
中添加vmin=vmin, vmax=vmax
,否则它将使用您拥有的值的默认值。如果您没有零值,则结果将不正确。 - Drummermean