0

I am plotting a geopandas choropleth plot, and the legend is not a continuous colour bar.

Here is the code:

fig, ax = plt.subplots(figsize = (10,10))
sm = gdf.plot(column = 'Average Crime',cmap = 'PuRd', ax = ax, legend = True, categorical = True)
ax.set(facecolor = 'white')

plt.show()

Here is how the image is shown: Image

How do I make the legend so that the legend is a continuous colour bar?

Thanks.

relayyyyy
  • 25
  • 4
  • How much data do you have? What output when categorical = False in plot? – stfxc Jan 11 '23 at 16:53
  • I have a gdf of crime and immigration numbers in London between 2005-2015. the output for categorical = False is the same. – relayyyyy Jan 11 '23 at 16:59
  • It looks like your data is not numeric, since the legend is sorting alphanumerically. It's a common mistake to read numbers as strings. Please make sure your `Average Crime` column is `int` or `float` or another numeric type. – SNygard Jan 11 '23 at 18:13
  • This question shows a continuous colorbar by default, so I think the issue is that pandas is assuming a categorical datatype (probably string instead of numeric): https://stackoverflow.com/questions/53158096/editing-colorbar-legend-in-geopandas – SNygard Jan 11 '23 at 18:17
  • Yea I fixed it by switched to numeric in the .csv – relayyyyy Jan 11 '23 at 20:50

0 Answers0