如何在Python中更改等值线图的图例文本?

时间:2015-11-17 17:04:53

标签: python matplotlib geopandas

我使用以下代码获得一个等值区域地图:

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

结果是:

enter image description here

但是如何将图例的文字更改为下面的地图而不是数字?

enter image description here

1 个答案:

答案 0 :(得分:1)

这个问题已经存在了一段时间,但我遇到了同样的问题。这解决了我的问题:

leg = ax1.get_legend()
leg.get_texts()[0].set_text('New label 1')
leg.get_texts()[1].set_text('New label 2')

等等,因为您想要更改多个标签。