14

I have a standard financial timeseries of data which has gaps for when the market is closed.

The problem is Chaco displays these gaps, I could use a formatter in matplotlib as follows and apply to the x-axis to get around this but I am unsure what I should do about this in Chaco.

In matplotlib:

class MyFormatter(Formatter):
    def __init__(self, dates, fmt='%Y-%m-%d %H:%M'):
        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)

What would be the efficient way to implement this in Chaco? Thanks

Fabian Fagerholm
  • 4,099
  • 1
  • 35
  • 45
Marcus1219
  • 217
  • 2
  • 8
  • With the caveat that I don't know Chaco, I expect that you'd want to use a 2D plot rather than an XY plot. The fundemental concept of an XY plot is that is to illustrate the relationship between continuous 'X" values. Just a guess, good luck! – David W Jun 15 '12 at 19:43
  • I can't see why this issue has been tagged as matplotlib? – pelson Jun 20 '12 at 21:39
  • see this question: http://stackoverflow.com/questions/2173632/python-chaco-axis-labels-time-formatting – Gerrat Jul 03 '12 at 20:10
  • Why don't you apply a [mask](http://docs.scipy.org/doc/numpy/reference/routines.ma.html) to your data using `numpy` and then just plot the masked array – abdulhaq-e Jul 05 '12 at 02:43

1 Answers1

2

pass the parameters like this

from enthought.chaco.scales.formatters import TimeFormatter
TimeFormatter._formats['days'] = ('%d/%m', '%d%a',)
Viral Shah
  • 2,263
  • 5
  • 21
  • 36
  • 1
    Generating a NAN series using Pandas Timeseries is another way to go [link] http://pandas.pydata.org/pandas-docs/stable/timeseries.html[/link]. – Marcus1219 Jan 03 '13 at 22:16