本文介绍了大 pandas 重建人物传说的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在绘制图形后,我得到一个图形图例,如下所示:

after plotting a figure I get a figure legend as below:

DataFrame1.plot(legend=False)
patch,labels=ax.get_legend_handels_labels()
DateFrame1.legend(loc='best')
plt.show()

如何删除(Temp,2005)中的'Temp',让它变成2005年?

How can I delete the 'Temp' in (Temp,2005) ,let become just 2005?

DataFrame1具有三个键:月,年,温度.

the DataFrame1 has three keys:Month,Year,Temp.

推荐答案

您非常亲密,您只需要更新年份的图例即可:

You were very close, you just need to update your legend with the years:

ax = df.plot()

years = [2005, 2007, 2008, 2009, 2011, 2012]
# you can get years from you dataframe (but without seeing the dataframe I can't say exactly how)
# legend also accepts a Series or numpy array
ax.legend(years, loc='best')
plt.show()

这篇关于大 pandas 重建人物传说的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 19:18