Bokeh Interactive mode: how to show only last values and not squeezing the whole dataset?

Adding a point to a dynamic plot the whole dataset visualization is squeezed to accomodate all points.
How is it possible to show only the last, say, 10000 points without removing older points from the dataset?
I am missing this figure property and I am sure it is under my nose…

This is the code, taken from


-- coding: utf-8 -

from bokeh.plotting import figure, curdoc
from bokeh.driving import linear
import random

p = figure(plot_width=400, plot_height=400)
r1 = p.line(, , color=“firebrick”, line_width=2)
r2 = p.line(, , color=“navy”, line_width=2)

ds1 = r1.data_source
ds2 = r2.data_source

def update(step):[‘x’].append(step)[‘y’].append(random.randint(0,100))[‘x’].append(step)[‘y’].append(random.randint(0,100))

curdoc().add_periodic_callback(update, 100)


(For the ones interested in the topic, this is the answer Bryan Van de ven sent to me on another thread)

You can try setting the .follow and .follow_interval on a DataRange1d:


This is similar to what you ask, it will allow you to control over the width of the x-range in data space, e.g. But there is nothing currently built into Bokeh that allows you to control by specifying “last N points”. For that you would have to write some kind of custom extension.

However, be advised that streaming data into the browser indefinitely is effectively an intentional memory leak – do it for long
enough or at a high enough rate and the browser will eventually become very unhappy. It’s for this reason that the .stream method on column data sources accept a “rollover” limit to automatically truncate data source columns. Of course, you could handle periodically truncating your
data source columns manually somehow too.

As an aside, there has been interest in developing the “dataframe” qualities of CDS on the JS side, so things like slices could be used to inform glyph renderers. It’s just obviously not a trivial task, and no one has been available to work on it yet.