pandas 来自 Geopandas GeoDataFame 的等值线图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31755886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Choropleth map from Geopandas GeoDataFame
提问by AJG519
I'm trying to make a choropleth map from polygons in a Geopandas GeoDataFrame. I want to symbolize the polygons by quantiles of a value in one of the GeoDataFrame columns. I'm trying to figure out different options and see what best fits my needs. Any advice on this would be greatly appreciated.
我正在尝试从 Geopandas GeoDataFrame 中的多边形制作等值线图。我想通过 GeoDataFrame 列之一中的值的分位数来符号化多边形。我试图找出不同的选择,看看什么最适合我的需求。对此的任何建议将不胜感激。
It appears that Geopandas does have some ability to do this already: http://nbviewer.ipython.org/github/geopandas/geopandas/blob/master/examples/choropleths.ipynb
看来 Geopandas 确实有能力做到这一点:http://nbviewer.ipython.org/github/geopandas/geopandas/blob/master/examples/choropleths.ipynb
tracts.plot(column='CRIME', scheme='QUANTILES', k=3, colormap='OrRd')
This works, although I can't find much documentation. I'd like to be able to add a legend that shows the quantile cut-off values, but it appears that the Geopandas plot currently only allows for legends based of categorical data. Does anyone have a work around for this?
这有效,尽管我找不到太多文档。我希望能够添加一个显示分位数截止值的图例,但似乎 Geopandas 图目前只允许基于分类数据的图例。有没有人解决这个问题?
Additionally, I'd like to be able to adjust the polygon outline width. Is this possible?
此外,我希望能够调整多边形轮廓宽度。这可能吗?
As an alternative option I've been playing around with is using polygon patches in matplotlib. This appears much more involved but does seem to offer more options to customize. If necessary to go down this route in order to build a legend I can follow-up with another question and will include my code so far.
作为我一直在玩的另一种选择是在 matplotlib 中使用多边形补丁。这似乎涉及更多,但似乎确实提供了更多的自定义选项。如果有必要沿着这条路线走下去以建立一个图例,我可以跟进另一个问题,并将包括我的代码。
Thanks for the help.
谢谢您的帮助。
回答by joris
The below patch is integrated in geopandas, so you can do now just:
以下补丁已集成在 geopandas 中,因此您现在可以执行以下操作:
tracts.plot(column='CRIME', scheme='QUANTILES', k=3, colormap='OrRd', legend=True)
I made a small patch to the plot_dataframefunction of geopandas to enable a legend when using a PySAL scheme. You can find it here: http://nbviewer.ipython.org/gist/jorisvandenbossche/d4e6efedfa1e4e91ab65(the adjustment is only in the few lines after if scheme is not None:).
我plot_dataframe对 geopandas的功能做了一个小补丁,以在使用 PySAL 方案时启用图例。您可以在这里找到它:http: //nbviewer.ipython.org/gist/jorisvandenbossche/d4e6efedfa1e4e91ab65(调整仅在 之后的几行中if scheme is not None:)。
This lets you do the following:
这使您可以执行以下操作:
ax = plot_dataframe(tracts, column='CRIME', scheme='QUANTILES', k=3, colormap='OrRd', legend=True)
to get such a figure:
得到这样一个数字:
回答by Dan
To adjust the polygon outline width, you can use "linewidth" like so:
要调整多边形轮廓宽度,您可以像这样使用“linewidth”:
tracts.plot(column='CRIME', scheme='QUANTILES', k=3, colormap='OrRd', linewidth=0.1)


