Hi,
Sorry for not including a minimal example earlier. Here is one below. It runs in a notebook cell:
import time
import numpy as np
from bokeh.io import push_notebook, show, output_notebook
from bokeh.models import HoverTool
from bokeh.plotting import figure
from bokeh.layouts import row, column
from bokeh.models import ColumnDataSource, Range1d, Slider, Circle, CheckboxButtonGroup, Select
import numpy as np
import pandas as pd
from scipy.stats import gaussian_kde
from bokeh.palettes import Blues9
from bokeh.plotting import figure, show
from bokeh.sampledata.autompg import autompg as dff
import bokeh
from bokeh.palettes import Sunset8
from bokeh.plotting import figure, show
import scipy
output_notebook()
import numpy as np
class bkapp:
df = pd.DataFrame({'x1': np.random.normal(size=10), 'x2': np.random.normal(size=10)})
def __init__(self):
self._theme_json = """
attrs:
figure:
background_fill_color: "#DDDDDD"
outline_line_color: white
toolbar_location: above
height: 500
width: 800
Grid:
grid_line_dash: [6, 4]
grid_line_color: white
"""
def periodically(self):
pass
# perform some update here
# self.source.data = ...
def __call__(self, doc):
self.source = ColumnDataSource(data=self.df)
xfig = figure(width=400, height=400)
xfig.x_range = Range1d(-5, 5)
xfig.y_range = Range1d(-5, 5)
xplot = xfig.circle(x='x1', y='x2', source=self.source, size=20, color="navy", alpha=0.5,
fill_alpha=0.2, line_color=None, radius=1.0,
hover_fill_color="black", hover_fill_alpha=0.7, hover_line_color=None)
doc.add_periodic_callback(self.periodically, 10)
doc.add_root(xfig)
show(bkapp(), notebook_url="http://localhost:8891") # put the address of the jupyter notebook you are on here!
So the idea is that periodically
will update the plot in real time. This part works. For example, if I update self.source
to change the data in the dataframe, that will automatically be reflected in the plot (xplot
).
However, the use case I am interested in is to have xplot
display some function of self.source.data
, not the data itself. So for example, suppose I want to plot the mean of x1
and x2
. All I want to do is plot that function of the source data, and have it change accordingly as I update self.source.data
in the periodic callback. Is that possible, or is there a better way?