code
-
-
original
import time import numpy as np from bokeh.plotting import cursession, figure, show, output_server from bokeh.models import GlyphRenderer x = np.linspace(0, 4*np.pi, 200) y = np.sin(x) output_server("simple_stream") p = figure(title="Simple streaming example") p.line(x, y, color="#2222aa", line_width=2) show(p) ds = p.select({"type": GlyphRenderer})[0].data_source while True: oldx = ds.data["x"] newx = np.hstack([oldx, [oldx[-1] + 4*np.pi/200]]) ds.data["x"] = newx ds.data["y"] = np.sin(newx) cursession().store_objects(ds) time.sleep(0.5)
-
convert to bokeh 0.11
#! conding utf-8 import time import numpy as np from bokeh.io import curdoc from bokeh.client import push_session from bokeh.models import GlyphRenderer from bokeh.plotting import figure, show x = np.linspace(0, 4*np.pi, 200) y = np.sin(x) p = figure(title="Simple streaming example") p.line(x, y, color="#2222aa", line_width=2) ds = p.select({"type": GlyphRenderer})[0].data_source def update(): oldx = ds.data["x"] newx = np.hstack([oldx, [oldx[-1] + 4*np.pi/200]]) ds.data["x"] = newx ds.data["y"] = np.sin(newx) # run every 5 milliseconds curdoc().add_periodic_callback(update, 5) session = push_session(curdoc(), 'simple-stream') # open the doc in browser session.show() # run forever session.loop_until_closed()
-
class GlyphRenderer(**kwargs)
-
base bokeh.models.renderers.DataRenderer
-
attr
-
data_source
local data source to use when rendering glyph on the plot -
glyph
the glyph to render, in conjunction with supplied data source and ranges -
hover_glyph
an optional glyph ofr inspected pointse.g. those that are being hoverd over by a HoverTool
-
level
specifies the level in which to render the glyph -
nonselection_glyph
an optional glyph used for explicitly non-selected points -
selection_glyph
an optional glyph used for selected points -
x_range_name
a particular(named) x-range to use for computing screen locations when rendering glyph on the plotif unset use the default x-range
-
y_range_name
see x_range_name
-