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.
You can set the labels on that object. Or, more succinctly: ax. set(xlabel="x label", ylabel="y label") . Alternatively, the index x-axis label is automatically set to the Index name, if it has one.
Pandas uses the plot() method to create diagrams. We can use Pyplot, a submodule of the Matplotlib library to visualize the diagram on the screen.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With