3

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?

2
  • 1
    not 100% sure, but did you try setting vmin and vmax? that's how its done in matplotlib. Commented Aug 27, 2022 at 15:58
  • You are right! I'm answering the question below. Commented Aug 29, 2022 at 15:33

1 Answer 1

2

@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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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