2

As suggested in the geopandas mapping tools documentation, I want to create a chloropleth map using a custom defined bin sizes:

world.plot(column='gdp_per_cap', cmap='OrRd', scheme='user_defined')

Indeed, 'user_defined' is mentioned explicitely in the geopandas plotting.py code on github.

However, when I attempt this, python (v 3.5, geopandas v 0.4.0) throws an error:

ValueError: Invalid scheme. Scheme must be in the set: dict_keys(['quantiles', 'equal_interval', 'fisher_jenks'])

Indeed, when inspecting the source code in my environment, the schemes are restricted to just these four.

How can it be that my Geopandas installation is not in sync with what's being suggested in the Geopandas docs and source code? According to Conda, I really have the latest version of Geopandas installed.

ANSWER:

I've cloned the Geopandas repo from Github. Using the plotting functionality from there, the following works:

world.plot(column='gdp_per_cap', cmap='OrRd', scheme='user_defined', classification_kwds={'bins':[1000, 10000, 100000]})
  • 1
    Im trying with: ud = pysal.esda.mapclassify.User_Defined(y=world.gpd_per_cap, bins=[200,250,300]), and then pass ud as scheme but i get another error. See pysal doc here. Have you seen this question and solution on SO: Plotting a choropleth map (with geopandas) using a user_defined classification scheme – BERA Jan 3 at 21:40
  • What is the error you are seeing? I have read the Q&A you are referring to. I don't think it should be necesary to mess with the Geoapandas source code as the top answer suggested. The Geopandas man pages suggest that 'user_defined' is already implemented. – HDR Jan 4 at 11:04
  • 1
    I cant check now. But it was something like: un or User_Defined has no attribute lower / or start /etc. Try it yourself, just import pysal, adjust bins and use scheme=un in the plot line – BERA Jan 4 at 11:06
  • I'll try that once back in the office. I think you're on the right track by first defining 'ud' as a Pysal object and then providing that to the plot function. – HDR Jan 4 at 16:00
  • 1
    Please write your answer as an answer, rather than inside the body of your question. – PolyGeo Jan 31 at 8:46
1

I've cloned the Geopandas repo from Github. Using the plotting functionality from there, the following works:

world.plot(column='gdp_per_cap', cmap='OrRd', scheme='user_defined', classification_kwds={'bins':[1000, 10000, 100000]})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.