reconstruction figure legend in pandas
pandas, python
Solution
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()
Problem
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() ``` How can I delete the 'Temp' in (Temp,2005) ,let become just 2005? the DataFrame1 has three keys:Month,Year,Temp.