3

I have a series of chaco plots that are dynamically updated with a timer object. I would like to set the Y ("value" in chaco speak) limits when the data changes.

When I initialise the plot object I call

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)

Then, later I update the data array with:

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)

This all work fine except I would like to auto range the plot afdter the data has been added. I have seen various pages suggest DataRange2D and value_mapper but I have no idea how to use them. Any help would be much appreciated.

mor22
  • 1,372
  • 1
  • 15
  • 32
  • I think that if you remove the statements `ylim.low = 0.001` and `ylim.high = 100` it will autorange. I've not been able to set initial limits than can be automatically changed. – jorgeca Jul 18 '13 at 13:47
  • Thanks, I've tried that and it works ok for a linear scale but not for loglog scale. – mor22 Jul 18 '13 at 14:27

1 Answers1

1

for auto ranging:

thisPlot.range2d.y_range.high = 'auto'

for specific range:

thisPlot.range2d.y_range.high = 1000

thisPlot.range2d.y_range.low = .001

you can switch between the two by creating a Bool trait "enableAutoRange." on trait change, you can set the plot values as stated above.

josh
  • 21
  • 3