How to set the axis limits
Get current axis via plt.gca(), and then set its limits: ax = plt.gca() ax.set_xlim([xmin, xmax]) ax.set_ylim([ymin, ymax])
Get current axis via plt.gca(), and then set its limits: ax = plt.gca() ax.set_xlim([xmin, xmax]) ax.set_ylim([ymin, ymax])
I had a problem with the answer by @mwaskorn, namely that g.set_xticklabels(rotation=30) fails, because this also requires the labels. A bit easier than the answer by @Aman is to just add plt.xticks(rotation=45)
Update: This answer is outdated since matplotlib version 3.5. The plot function now handles datetime data directly. See https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.pyplot.plot_date.html The use of plot_date is discouraged. This method exists for historic reasons and may be deprecated in the future. datetime-like data should directly be plotted using plot. If you need to plot plain numeric data as … Read more