Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choropleth map from Geopandas GeoDataFame

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.

It appears that Geopandas does have some ability to do this already: 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?

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.

Thanks for the help.

like image 555
AJG519 Avatar asked Jul 31 '15 22:07

AJG519


1 Answers

The below patch is integrated in geopandas, so you can do now just:

tracts.plot(column='CRIME', scheme='QUANTILES', k=3, colormap='OrRd', legend=True)

I made a small patch to the plot_dataframe function 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:).

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:

enter image description here

like image 151
joris Avatar answered Nov 17 '22 23:11

joris