【问题标题】:Change the size of the colorbar in geopandas plot.I got error "Unknown property cax"更改 geopandas 图中颜色条的大小。我收到错误“未知属性 cax”
【发布时间】:2019-08-20 18:10:12
【问题描述】:

我想在 geopandas.plot() 函数中调整颜色条的大小。

我阅读了 geopandas 的关于颜色条调整的 Github 页面。 https://github.com/geopandas/geopandas/pull/894

然后编写如下代码

import geopandas as gp
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.pyplot as plt
shp=gp.read_file("PropRepShape.shp",encoding="UTF-8")
fig, ax = plt.subplots(1,1)
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.2) # depends on the user needs
shp.plot("P_NUM",ax=ax,cax=cax,legend=True,cmap=cmap)

“PropRepShape.shp”可从 https://github.com/ShingObt/2019JapanHOCElectionMap/tree/master/Shapefile

然后我最终收到错误消息

AttributeError: Unknown property cax

通过删除cax=cax,我可以生成地图,但颜色条的大小没有调整。

能否告诉我在 gp.plot 中成功使用 cax 参数的方法?

【问题讨论】:

标签: python geopandas


【解决方案1】:

cax 属性已在 geopandas 0.5.0 中实现(参见changelog)。您必须更新到 0.5.1(稳定版)或 0.6.0rc1(候选发布版)才能在您的代码中使用 cax

conda install -c conda-forge geopandas=0.5.1

【讨论】:

  • 谢谢!我将 geopandas 更新到 0.5.1 并且 cax 运行良好。从下次开始,我会仔细检查版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-08-19
  • 1970-01-01
  • 1970-01-01
  • 2015-03-06
  • 2016-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多