GeoPandas – Forcing a Choropleth to Use a Legend with a Greater Range

choroplethgeopandaspython

I have a list of cities, and I'm trying to graph individual choropleth maps for each city's census tracts (coloring is based on their density column).

However, I'd like the choropleth to color the census tracts (polygons) based on the entire range of density for all cities, not just the city being graphed.

For example: If Dallas, TX has a minimum density of 0 and a maximum is 5000, and 5000 is the largest density out of my list of cities, I'd like the choropleth to use that number when coloring in census tracts for each individual city. So if I plot Irving, TX, which would have a maximum density of 200, that is much less that 5000, and the coloring should reflect that.

But right now, if I run:

irving.plot(columns='density', ax=ax, cmap='cool', legend=True)

The choropleth will color Irving's census tracts with 0 as the minimum and 200 as the maximum. How can I force the maximum to be what I want and have the choropleth's coloring reflect this?

Best Answer

@Bert Coerver is right, vmax must be passed as an argument. According to the docs for geopandas.plot():

vmax : None or float (default None)
    Maximum value of cmap. If None, the maximum data value in the column to be plotted is used.

All I needed to do was find the global maximum value (global_max) of density for my cities, and set that value with vmax=global_max when using geopandas.plot(). The code below is an example:

irving.plot(columns='density', ax=ax, cmap='cool', legend=True, vmax=global_max)