处理Chaco中的时间序列间隙

14

我有一组标准的金融时间序列数据,其中包含市场关闭时的间隙。

问题是,Chaco会显示这些间隙。在matplotlib中,我可以使用以下代码应用于x轴来避免这个问题,但是我不确定在Chaco中应该怎么做。

在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)

如何在 Chaco 中高效地实现这个功能?谢谢。


请注意,我不了解Chaco,但我认为您可能希望使用2D图而不是XY图。 XY图的基本概念是说明连续“X”值之间的关系。这只是一个猜测,祝你好运! - David W
我不明白为什么这个问题被标记为matplotlib? - pelson
请查看以下问题:https://dev59.com/FkvSa4cB1Zd3GeqPga4l - Gerrat
为什么不使用 numpy 对数据应用 掩码,然后只需绘制掩码数组即可。 - abdulhaq-e
1个回答

2
像这样传递参数。
from enthought.chaco.scales.formatters import TimeFormatter
TimeFormatter._formats['days'] = ('%d/%m', '%d%a',)

1
使用Pandas Timeseries生成NAN系列是另一种方法[链接]http://pandas.pydata.org/pandas-docs/stable/timeseries.html[/链接]。 - Marcus1219

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接