[英]How to change the text of the legend of a choropleth map in Python?
I get one choropleth map using the following code: 我使用以下代码获得一个等值区域地图:
%matplotlib inline
import seaborn as sns
import pandas as pd
import pysal as ps
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as pet
imd_shp = 'desktop/sgfwu/E07000222_IMD/shapefiles/E07000222.shp'
imd = gpd.read_file(imd_shp)
imd = imd.set_index('LSOA11CD')
imd.plot(column='imd_score', scheme='fisher_jenks', alpha=0.8, k=7,
colormap=plt.cm.Blues, legend=True, axes=ax1)
The result is: 结果是:
But how can I change the text of the legend to the words like the map below, rather than numbers? 但是,如何将图例的文字更改为下面的地图而不是数字呢?
This question has been here for a while, but I just had the same problem. 这个问题已经存在了一段时间,但我遇到了同样的问题。 This solved it for me: 这解决了我:
leg = ax1.get_legend()
leg.get_texts()[0].set_text('New label 1')
leg.get_texts()[1].set_text('New label 2')
and so on for as many labels as you want to change. 等等,您可以根据需要更改标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.