Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chaco plot range dynamic update

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.

like image 345
mor22 Avatar asked Dec 21 '25 06:12

mor22


1 Answers

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.

like image 65
josh Avatar answered Dec 22 '25 22:12

josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!