2017-08-30 52 views
0

传说添加到图表中matplotlib我想要一个传说添加到频率分布图 enter image description here如何在python

这是我使用的代码。

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

我想补充表示什么0代表一个传奇,1个代表等,任何人都可以请帮我做到这一点?

+1

这不是一个真正的传奇。您应该考虑在图表中添加[text](https://matplotlib.org/users/text_intro.html) –

+1

您是否尝试过使用'plt.xticks([1,2,3,4],['primary', 'secondary','tertiary','quaternary'])'? – Guillermo

+0

@Guillermo - 谢谢。这工作。我会代表你回答这个问题并接受。 –

回答

0

正如@Guillermo提到的,我试过

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

这为我工作。