date-gaps in timeseries

Hi,

I want to plot some timeseries (eg. stockcharts). I use now DateLocator/Formatter, it works fine for me with the exeption, that dataless periods on X-Axis (eg. weekends) are also plotted. Is there an easy way to suppress them?

regards

try using plot_date() function instead of plot()

···

On Sun, 2007-06-10 at 09:49 +0200, rolandreichel wrote:

Hi,

I want to plot some timeseries (eg. stockcharts). I use now
DateLocator/Formatter, it works fine for me with the exeption, that
dataless periods on X-Axis (eg. weekends) are also plotted. Is there an
easy way to suppress them?

regards

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Plot numpy.arange(len(xdata)) vs y and use a custom tick locator to
format the integer index to date strings. Some of the code below is
using svn (eg the csv2rec stuff) but the core logic of formatting date
strings from integers works with any reasonably current mpl.

# plot dates evenly spaced, eg skipping weekends
import numpy
from matplotlib.mlab import csv2rec
from pylab import figure, show
from matplotlib.dates import Formatter

r = csv2rec('data/msft.csv')[-40:]

class MyFormatter(Formatter):
    def __init__(self, dates, fmt='%Y-%m-%d'):
        self.dates = dates
        self.fmt = fmt

    def __call__(self, x, pos=0):
        'Return the label for time x at position pos'
        ind = int(round(x))
        if ind>=len(self.dates) or ind<=0: return ''

        return self.dates[ind].strftime(self.fmt)

formatter = MyFormatter(r.date)

fig = figure()
ax = fig.add_subplot(111)
ax.xaxis.set_major_formatter(formatter)
ax.plot(numpy.arange(len(r)), r.close, 'o-')
fig.autofmt_xdate()
show()

···

On 6/10/07, rolandreichel <rolandreichel@...273...> wrote:

I want to plot some timeseries (eg. stockcharts). I use now
DateLocator/Formatter, it works fine for me with the exeption, that
dataless periods on X-Axis (eg. weekends) are also plotted. Is there an
easy way to suppress them?