Chaco绘图范围动态更新

3

我有一系列使用计时器对象动态更新的chaco图表。在数据发生变化时,我想要设置Y轴(chaco术语中的"value")的范围限制。

当我初始化图表对象时,我调用:

obj.alldata = ArrayPlotData(frequency=frequencies)
# Cycle through the channels and add a set to the alldata object    
for [i,v] in enumerate(channels):
    setname="amplitude{:d}".format(v)
    obj.alldata.set_data(setname, empty_amplitude)

for c in config['plots']:
    thisplot=Plot(obj.alldata)
    xlim=thisplot.index_mapper.range
    xlim.low=1
    xlim.high=1000
    ylim=thisplot.value_mapper.range
    ylim.low=0.001
    ylim.high=1000

thisplot.plot(("frequency", initdata),
                 name="Spec",
                 value_scale="log",
                 index_scale="log")

container.add(thisplot)

接着,我后来使用以下代码更新了数据数组:

def onTimer(self, *args):
    '''This is fired every time the timer is triggered 
    '''
      # Get the data 


    for [i,v] in enumerate(self.channels):
        data=getsimdata(self.s,v,int(self.config['numsamp']))
        self.alldata.set_data(setname,data)

这一切都很好,除了我想在数据添加后自动调整图表范围。我看过各种页面建议使用 DataRange2Dvalue_mapper,但我不知道如何使用它们。非常感谢您的帮助。

我认为如果你删除语句 ylim.low = 0.001ylim.high = 100,它将自动调整范围。 我无法设置初始限制,因此它可以自动更改。 - jorgeca
谢谢,我已经尝试过了,对于线性比例尺来说可以正常工作,但是对于双对数比例尺不行。 - mor22
1个回答

1

自动范围:

thisPlot.range2d.y_range.high = 'auto'

指定范围:

thisPlot.range2d.y_range.high = 1000

thisPlot.range2d.y_range.low = .001

您可以通过创建一个布尔特征 "enableAutoRange" 来在两者之间切换。在特征更改时,您可以按照上述方式设置图表值。


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