如何在Python中更改Choropleth贴图的图例文本? [英] How to change the text of the legend of a choropleth map in Python?

查看:83
本文介绍了如何在Python中更改Choropleth贴图的图例文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码获得一个choropleth映射:

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)

结果是:

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

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.

这篇关于如何在Python中更改Choropleth贴图的图例文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆