簡體   English   中英

如何在python中的matplotlib中向圖表添加圖例

[英]How to add a legend to a chart in matplotlib in python

我正在嘗試在頻率分布圖中添加圖例 在此處輸入圖片說明

這是我正在使用的代碼。

train_df.Medu.value_counts().plot(kind='bar', alpha=0.6)
plt.title("Distribution of Mother's education")
plt.legend()

我想添加一個圖例,顯示0代表什么,1代表什么,等等。任何人都可以幫助我實現這一目標嗎?

正如@Guillermo所提到的,我嘗試了

plt.xticks([1, 2, 3, 4], ['primary', 'secondary', 'tertiary', 'quaternary'])

這對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM