How to skip empty dates (weekends) in a financial Matplotlib Python graph?


ax.plot_date((dates, dates), (highs, lows), '-')

I'm currently using this command to plot financial highs and lows using Matplotlib. It works great, but how do I remove the blank spaces in the x-axis left by days without market data, such as weekends and holidays?

I have lists of dates, highs, lows, closes and opens. I can't find any examples of creating a graph with an x-axis that show dates but doesn't enforce a constant scale.

12/12/2010 2:02:56 PM

Accepted Answer

I think you need to "artificially synthesize" the exact form of plot you want by using xticks to set the tick labels to the strings representing the dates (of course placing the ticks at equispaced intervals even though the dates you're representing aren't equispaced) and then using a plain plot.

8/13/2009 5:56:33 PM

There's an example of how to do this on the Matplotlib site:

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow