我有一系列使用计时器对象动态更新的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)
这一切都很好,除了我想在数据添加后自动调整图表范围。我看过各种页面建议使用
DataRange2D
和 value_mapper
,但我不知道如何使用它们。非常感谢您的帮助。
ylim.low = 0.001
和ylim.high = 100
,它将自动调整范围。 我无法设置初始限制,因此它可以自动更改。 - jorgeca