Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh - Plotting Data with Gaps

Tags:

python

bokeh

Is there a way to have Bokeh plot data that has gaps in it? See the below screenshot from a Excel plot for an example. I tried using None values, but it just plotted zero values.

x_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

y_data = [4, 1, 2, 3, , , , 4, 4, 5]

Excel Plot

like image 991
feik Avatar asked Mar 12 '15 02:03

feik


1 Answers

You can use nan (here I've used np.nan, after import numpy as np, but float("nan") would work as well):

>>> y_data = [4, 1, 2, 3, np.nan, np.nan, np.nan, 4, 4, 5]
>>> x_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> p1 = figure(plot_width=600, plot_height=400)
>>> p1.line(x_data, y_data, size=12, color="blue")

gives

demo of gap

like image 110
DSM Avatar answered Oct 02 '22 15:10

DSM