小编Mar*_*219的帖子

处理Chaco的时间序列差距

我有一个标准的金融时间序列数据,这些数据在市场关闭时存在差距.

问题是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)
Run Code Online (Sandbox Code Playgroud)

在Chaco中实现这一目标的有效方法是什么?谢谢

python matplotlib chaco

14
推荐指数
1
解决办法
672
查看次数

顺序排列扭曲的多个延迟

目前我仍然是一个扭曲的初学者,这让我感到烦恼.

我正在通过TCP发送一系列命令并等待lineRecieved阅读器的响应,这可能需要几秒钟的时间来处理和到达,所以我把它包装在一个deferred中.第一个延迟工作正常但第二个工作正在激活,因为第一个仍处理导致垃圾,因为端点一次只能处理一个命令.asysc系统中的预期行为,但不是我需要发生的行为.如果我有一个或两个命令,我可以使用deferredChain来处理,但由于我可能有几十个命令按顺序运行,我担心这会变成无法维护的意大利面.

干净的方法是什么?

非常感谢

示例代码

def connectionMade(self):
    self.fire_def('command1')
    print'fire command 2'
    self.fire_def('command2')#Fires when command one is running

def fire_def(self,request):
    d = self.getInfo(request)
    d.addCallback(self.print_result)
    return d

def print_result(result):
    print result


def getInfo(self,request):
    print 'sending', request
    self.d  = defer.Deferred()
    self.sendLine(request)
    return self.d

def lineReceived(self, line):
    line = line.strip()
     self.buffer.append(line)
    if self.d is None:
        return
    if  'result_I_want' in self.buffer:
        print 'Firing Callback'
        self.d.callback(self.buffer)
Run Code Online (Sandbox Code Playgroud)

python twisted

4
推荐指数
1
解决办法
1064
查看次数

标签 统计

python ×2

chaco ×1

matplotlib ×1

twisted ×1