绘制图形后,我得到一个图形图例如下:
DataFrame1.plot(legend=False)
patch,labels=ax.get_legend_handels_labels()
DateFrame1.legend(loc='best')
plt.show()
Run Code Online (Sandbox Code Playgroud)
如何删除(Temp,2005)中的'Temp',让我们成为2005年?
DataFrame1有三个键:Month,Year,Temp.
你非常接近,你需要用这些年来更新你的传奇:
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()
Run Code Online (Sandbox Code Playgroud)