Hello, I am plotting a simple dataset as below and want to use a taptool to select data. Later I plan to assign something (a picture to display for example) to the selected marker. I also have two widgets to change the plot axes.
When the widgets are in the initial state, plot appears as it suppose to be. Taptool correctly selects the data points. When I change an axis or axes from the widgets, and I select a point, data points on the graph replot as in the initial state! When I unselect the point, data points go back to correct data points from the widget. I tried this with customJS as well as pure python same results I obtained. am I missing something?
I run: Bokeh server version 3.5.0 (running on Tornado 6.4.1)
Below is the complete code:
from bokeh.models import ColumnDataSource, Select, TapTool
from bokeh.plotting import figure, curdoc
from bokeh.layouts import column, row
data = {
'Formation Pres., psia': [9, 18, 26, 36, 45],
'Pstar, psia': [10, 20, 30, 40, 50],
'Probe MD, m': [5, 4, 3, 2, 1],
'Probe TVD, m': [7, 3, 4, 1, 3],
'DD Mobility, mD/cP': [2, 4, 6, 8, 10],
'color': ['red', 'green', 'blue', 'orange', 'purple'],
'Size': [10, 20, 30, 40, 50],
'legend': ['A', 'B', 'C', 'D', 'E'],
'marker': ['circle', 'triangle', 'square', 'diamond', 'star']
}
XYlist = ['DD Mobility, mD/cP', 'Formation Pres., psia', 'Probe MD, m', 'Probe TVD, m', 'Pstar, psia']
X = Select(value='Pstar, psia', options=list(XYlist), title="X Axis")
Y = Select(value='Probe MD, m', options=list(XYlist), title="Y Axis")
src = ColumnDataSource(data=data)
def make_plot(src, xx, yy):
p = figure(tools=["save", "pan", "box_zoom", "reset", "wheel_zoom"], width=400, height=400)
renderer = p.scatter(x=xx, y=yy, alpha=1.0, source=src, fill_alpha=0.5, size='Size', legend_field='legend', marker='marker', color='color', line_color='color', line_width=1.1,
selection_color="color", selection_fill_alpha=0.6, selection_line_color="#580F41", selection_line_alpha=1.0, selection_line_width=3.0,
nonselection_color="color", nonselection_fill_alpha=0.6, nonselection_line_color="color", nonselection_line_alpha=1.0, nonselection_line_width=1.2)
# Set initial axis labels
p.xaxis.axis_label = xx
p.yaxis.axis_label = yy
# Add TapTool
tap_tool = TapTool(renderers=[renderer])
p.add_tools(tap_tool)
return p, renderer
# Create the initial plot
p, renderer = make_plot(src, X.value, Y.value)
def update_plot(attr, old, new):
renderer.glyph.x = X.value
renderer.glyph.y = Y.value
p.xaxis.axis_label = X.value
p.yaxis.axis_label = Y.value
X.on_change('value', update_plot)
Y.on_change('value', update_plot)
layout_tab = column(row(X, Y), p)
curdoc().add_root(layout_tab)