I came across a strange auto-update behaviour of Bokeh server streaming plots. Essentially, with a streaming plot the axes ranges are updated automatically. When the ranges are changed manually, the new ranges persist only until the data is updated, again. At that point, also the axes ranges are updated.
This behaviour can be "turned off" by using any of the pan, or zooming tools. For instance, if you zoom out of a plot, the axes ranges are no updated automatically anymore, and the manually changed range are locked in.
However, after using the Reset tool, the old behaviour is activated again.
The code below shows the behaviour. Start the script and click on the button. The y-axis range changes to 0:50. After the data is updated, the range jumps back to its original setting. However, if you pan the plot and then click the button, the range stays at 0:50 until you hit reset.
I'm wondering now how to turn of the auto range update after the button is clicked.
# Import libraries
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource, Range1d, LinearAxis
from bokeh.models.widgets import Button
from bokeh.layouts import layout
from bokeh.plotting import figure
from random import randrange
# Create figure
f=figure()
# Create ColumnDataSource
source = ColumnDataSource(dict(x=[],y=[]))
# Create Line
f.line(x='x',y='y',source=source)
def update_all():
new_data=dict(x=[randrange(1,10)],y=[randrange(1,10)])
source.stream(new_data,rollover=15)
# Update axis function
def update_axis():
f.y_range.start = 0
f.y_range.end = 50
# Create Button
button = Button(label='Set Axis')
# Update axis range on click
button.on_click(update_axis)
# Add elements to curdoc
lay_out=layout([[f, button]])
curdoc().add_root(lay_out)
curdoc().add_periodic_callback(update_all,2000)
Having both x and y range initialized seems to disable the 'auto-update' behavior:
f = figure(x_range=[0, 10], y_range=[0, 100])
Does not matter what the actual ranges are or if you change them later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With