Search code examples
bokehbokehjs

Bokeh Server Plot - How to make new values appear in the center with a fixed axis range


I want to create a plot that shows the live metering data I am getting from an electricity meter.

I already figured out how to have a plot in bokeh, that updates every x seconds with new values, but now I want to have the new values always be at a fixed point in the plot, while the range of the axis does not increase. I fixed the range by adding x_range=[0, 10] to the figure, however that plot is running out of the screen and I have to manually follow it. How do I change it so it follows it automatically?

Is that even possible in bokeh or should I be using something different for my project?


Solution

  • Use a default DataRange1d range (i.e. do not set the range to a fixed interval) and then set the follow property on the range. You can also set follow_interval to specify how far back the range should trail the latests data.

    p.x_range.follow = "end"
    p.x_range.follow_interval = 100
    

    For a complete demonstration see the OHLC ticker example.