如何解决如何更改GeoPandas Choropleth图的颜色栏的字体大小
当我尝试使用legend_kwds参数更改颜色条的字体大小时,我不断收到此错误
TypeError: init ()获得了意外的关键字参数'fontsize'
ax = df.plot(figsize=(20,16),alpha=0.8,column='value',legend=True,cmap='OrRd',legend_kwds={'fontsize':20})
plt.show()
有人知道我如何使用GeoPandas增加颜色栏的字体大小吗?我似乎找不到有效的关键字。我正在使用GeoPandas 0.8.1和Matplotlib 3.3.1。
解决方法
您可以使用matplotlib解决方法,而不是在单个语句中通过geopandas的plot函数传递所有复杂参数。
import numpy as np
import geopandas as gpd
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
# for demo purposes,use the builtin data
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
africa = world[world.continent=='Africa']
maxv,minv = max(africa.pop_est),min(africa.pop_est)
fig,ax = plt.subplots(figsize=(7,6))
divider = make_axes_locatable(ax)
# create `cax` for the colorbar
cax = divider.append_axes("right",size="5%",pad=0.1)
# plot the geodataframe specifying the axes `ax` and `cax`
africa.plot(column="pop_est",cmap='magma',legend=True,\
vmin=minv,vmax=maxv,ax=ax,cax=cax)
# manipulate the colorbar `cax`
cax.set_ylabel('pop_est',rotation=90)
# set `fontsize` on the colorbar `cax`
cax.set_yticklabels(np.linspace(minv,maxv,10,dtype=np.dtype(np.uint64)),{'fontsize': 8})
plt.show()
输出图:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。