views:

672

answers:

4
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 I also need the option to 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.

I'd appreciate any help!

+1  A: 

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.

Alex Martelli
+1  A: 
Autoplectic
+2  A: 

I will typically use numpy's NaN (not a number) for values that are invalid or not present. They are represented by matplotlib as gaps in the plot and numpy is part of pylab/matplotlib

>>> import pylab
>>> xs = pylab.arange(10.) + 733632. # valid date range
>>> ys = [1,2,3,2,pylab.nan,2,3,2,5,2.4] # some data (one undefined)
>>> pylab.plot_date(xs, ys, ydate=False, linestyle='-', marker='')
[<matplotlib.lines.Line2D instance at 0x0378D418>]
>>> pylab.show()
bpowah
+1  A: 

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

http://matplotlib.sourceforge.net/examples/api/date_index_formatter.html