I'm currently trying to plot the average and max of of a dataframe in 2 graphs with shared selection. On selection of in graph 1, I want to plot the data that is being averaged in graph 2. I'm getting the graphs and selection but it doesn't seems to update the graph with a selection in spyder. Below my code.
import pandas as pd
import numpy as np
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show
from bokeh.layouts import row
from bokeh.io import curdoc
# data for plot 2
df2 = pd.DataFrame(list([[1,1,2,3],[3,4,4,5]]))
source2 = ColumnDataSource(
data=dict(
x=list(df2.index.values),
y=list(df2.iloc[:,0].values)
)
)
# data for plot 1 & 0
df1 = np.mean(df2)
df0 = np.max(df2)
source1 = ColumnDataSource(
data=dict(
x=list(range(0,df1.shape[0])),
y=list(df1.values),
y1=list(df0.values),
)
)
# Plot graph one with data from df1 and source 1 as barplot
plot1 = figure(plot_height=300, plot_width=400, tools="box_select")
barglyph = plot1.circle(x='x',y='y',source=source1)
# Plot graph one with data from df1 and source 1 as barplot
plot0 = figure(plot_height=300, plot_width=400, tools="box_select")
barglyph = plot0.circle(x='x',y='y1',source=source1)
# Plot graph two with data from df2 and source 2 as line
plot2 = figure(plot_height=300, plot_width=400, title="myvalues",
tools="box_zoom,reset,save,wheel_zoom,hover")
r1 = plot2.line(x='x',y='y',source =source2, line_alpha = 1, line_width=1)
# safe data from plot 2 for later change in subroutine
ds1 = r1.data_source
def callback(attr, old, new):
patch_name = source1.data['colnames'][new['1d']['indices'][0]]
ds1.data['y'] = df2[patch_name].values
barglyph.data_source.on_change('selected',callback)
show(row(plot0,plot1,plot2))
curdoc().add_root(row(plot0,plot1,plot2))
If I run this in jupyter I get the error: AttributeError: 'Document' object has no attribute 'references'