I want to change the x axis range as part of a plot update in jupyter.
My update function for plotting a time series (line is an instance of multi_line
):
def update_plot(meta, data, fig, line, window_length=3.0):
fs = meta["format"]["sample rate"]
data = np.asarray(data).transpose()[4:8]
x, y = dsp.time_series(data, fs)
x = np.tile(x, (y.shape[0], 1))
line.data_source.data['xs'] = x.tolist()
line.data_source.data['ys'] = y.tolist()
if x.max() >= window_length:
fig.x_range = Range1d(x.max() - window_length, x.max())
push_notebook()
However, while this updates the plot with the new data, it does not actually set the x axis limits as expected. I've tried How can I accomplish `set_xlim` or `set_ylim` in Bokeh? however it doesn't actually update my plot. One option would be to slice the plotted data, however I want all the data to be available if the user zooms out.