[英]How to change the text of the legend of a choropleth map in Python?
我使用以下代碼獲得一個等值區域地圖:
%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)
結果是:
但是,如何將圖例的文字更改為下面的地圖而不是數字呢?
這個問題已經存在了一段時間,但我遇到了同樣的問題。 這解決了我:
leg = ax1.get_legend()
leg.get_texts()[0].set_text('New label 1')
leg.get_texts()[1].set_text('New label 2')
等等,您可以根據需要更改標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.