Hey,
I am trying to have a gridplot with potentially a large number of subplots. Each of these subplots again contains several lines. Altogether I assume this may be considered as “a lot of data” that needs to be transferred.
Each line is updated periodically and the changes are displayed in the respective subplot. From what I understand, each line is updated once its data is changed. This repeated synchronisation I assume to be the source of speed issues. My question therefore is: Is there a way to prevent the updates being synced with the plot until I explicitly give a command?
The following code is an example demonstrating the issue. On my laptop, each cycle takes in-between 0.25 to 0.4 seconds.
import numpy as np
import time
from bokeh.io import gridplot
from bokeh.client import push_session
from bokeh.plotting import figure, curdoc
"""
Plots a bunch of dancing gaussians.
Currently, it's a bit slow and some of the plots are only displaying after refreshing the browser
"""
def demo_online_gaussians_v1(n_points = 100, n_gaussians = 10, n_plots = 12, (x_min, x_max) = (-5, 5)):
#### Destination Setup ####
session = push_session(curdoc(),session_id="Test1")
#### Plot Setup ####
x = np.linspace(x_min, x_max, n_points)
offsets = np.arange(n_gaussians)*2*np.pi/(n_gaussians+1)
axs = [figure(width = 300, height=300) for _ in xrange(n_plots)]
fig = gridplot([axs[0:4], axs[4:8], axs[8:12]]) # changed to accumulate all n_plots
lines_plots = {}
#### Show the plots with initial content ####
session.show()
#### update plots in loop ####
for t in np.linspace(0, 50, 300):
means = np.sin(t+offsets)
stds = 1
data = np.exp(-(x[:, None] - means)**2 / 2*stds**2) / np.sqrt(2*np.pi*stds**2)
t_start = time.time()
for ax in axs:
# Get new data
# Plot
if t==0:
lines_plots[ax] = [ax.line(x, data[:, i], line_width=4) for i in xrange(n_gaussians)]
else:
for i, r in enumerate(lines_plots[ax]):
r.data_source.data["y"] = data[:, i]
print 'Time to update plot: %s' % (time.time() - t_start)
time.sleep(1.0)
if __name__ == '__main__':
demo_online_gaussians_v1(n_plots = 12,n_gaussians = 10)