3

I have a choropleth map which displays crime percentage change. It is plotted from a geodataframe and the choropleth intervals are determined in the background by Python.

Unfortunately, the first label in the legend (for white polygons) shows "0.00 - -50.00" when it is in actual fact starting from -286, not 0. Similarly, the last label shows "30.18 - nan".

How do I change these to "Less than -50.0" and "Greater than 30.18"?

Percentage Change Map

Please see my code below:

f, ax = plt.subplots(1, figsize=(16, 16))

PoliceDataMap.plot(column='PercChange', scheme='quantile', k=5, legend=True, axes=ax, colormap='Reds', linewidth=0.2, alpha=0.8)

ax.set_axis_off()

ax.set_title("Crime Percentage Change between Jan 2011 & Jan 2015", **TitleFont)

plt.axis('equal')
plt.show()
0

You can modify items of the legend manually:

new_labels=[
            '<50',
            '-50 - -27.48',
            '-27348 - -4.75',
            '-4.76 - 30.18',
            '>30.18'
]

leg = ax.get_legend()
for text, label in zip(leg.get_texts(), new_labels):
    text.set_text(label)

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.