View Full Version : [SOLVED] [Python, Matplotlib]Text on X-axis overlaps

February 8th, 2012, 03:03 PM

I am creating a plot in Python using matplotlib and its plot_date (http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.plot_date) function as follows (the resulting plot is attached below):

plt.plot_date(date_line, numbers1, fmt='b-', tz=None, xdate=True, ydate=False, hold=None)
plt.plot_date(date_line, numbers2, fmt='r--', tz=None, xdate=True, ydate=False, hold=None)
# this 4 times for all the plots.
As you can see in the attached image, the dates on the X-axis overlap so that you can't read any of it anymore.

Is there a way to display only what fits? So for example only the first and the last date, or when the data spans several years display only the whole years, and not every day..

All tips are welcome!

February 8th, 2012, 10:21 PM
the usual way to handle dates on the axis is to angle them so more fit properly:
the example also shows how to distance the dates

you can also combine it tight_layout to get better automatic results with multiple plots (if your matplotlib is new enough)

February 10th, 2012, 10:25 AM
Thanks madcow108!

autofmt_xdate() helped fixing the problem. In the attachement there is an example of how it looks now.

Have a beautiful day!