ColumnDataSource.stream don't change y-axis position

Hey everyone,

I am having a question regarding the stream method of a ColumnDataSource. I set up a figure with 10 different lines that get a new value every 10 seconds. The new value is coming in with the stream method. When new values are put into the ColumnDataSource, the plot is changing the y-axis if needed. My issue is, that one of the ten lines has relativly high values. If I set the line to invisible and set the y-axis range to a smaller range, the range jumps back up with the next call of the stream method. In my case, that is a little annoying. Is it possible to somehow stop the plot from changing the y-axis automatically with every call of the stream method? The relevant code parts are following.
Thank you very much.

main.py

dataframe = {'x' : [], 'L1' : [], 'L2' : [], 'L3' : [], 'L4' : [], 'L5' : [], 'L6' : [], 'L7' : [], 'L8' : [], 'L9' : [], 'L10' : []}
sourcePlot = ColumnDataSource(dataframe)

xRange = Range1d(start=datetime.datetime.now() - datetime.timedelta(minutes=15), end=datetime.datetime.now())
plot = figure(name='kwhPlot', x_axis_type='datetime', plot_width=1500, plot_height=500, title="kWh live", x_axis_label='Time', y_axis_label='[kWh]', x_range=xRange, toolbar_location=None)

dataReceiver (is called every 10 seconds with the new data)

newDataframe = {'x' : [date], 'L1' : [y1], 'L2' : [y2], 'L3' : [y3], 'L4' : [y4], 'L5' : [y5], 'L6' : [y6], 'L7' : [y7], 'L8' : [y8], 'L9' : [y9], 'L10' : [y10]}
sourcePlot.stream(newDataframe, 1000)

So what’s happening is that you aren’t explicitly setting a Range1d to your figure’s y axis. That means by default DataRange model is assigned to it. The default behaviour of the DataRange1d is to “follow all renderers” i.e. every renderer on the figure.

Fortunately, the DataRange model has a renderers property. So you can tell it to not follow certain renderers. Something like (sorry have to paraphrase, very pressed for time):

f = figure()
rend1 = f.line(...) #thing you want the y axis to follow
rend2 = f.line(...) #thing you don't want the y axis to follow
f.y_range.renderers = [rend1] #explicitly say don't follow rend2
2 Likes

Thanks that helped me a lot!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.