(Bokeh3.2.2) Passing a pandas dataframe to ColumnDataSource( so that the df_data can be seen as a Tooltip),results in an RuntimeError(source = ColumnDataSource(data=dict(x=a_list, y=an_array)when the source is passed to a figure.circle object.How to show df_data as a tooltip?
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
# Create a ColumnDataSource from your DataFrame
source = ColumnDataSource(df)
TOOLTIPS = """
<div>
<div>
<span style="font-size: 17px; font-weight: bold;">@Time:@Spot</span>
<span style="font-size: 15px; color: #966;">@Strike:(@cLtp, @pLtp)[@cSellOi{(0.00 a)}, @pSellOi]{(0.00 a)}</span>
</div>
</div>
"""
# Create the figure
plot = figure(
title=f'{indexCode}({spotPrice})',
x_axis_label="Time",
x_axis_type="datetime",
y_axis_label="cSellOi",
background_fill_color="black",
sizing_mode="stretch_both",
tooltips=TOOLTIPS
)
# Use the ColumnDataSource as the data source for glyphs
plot.circle(x='Time', y='cSellOi', source=source, size=10, color="white")
# Show the plot
show(plot)
df =
Time Spot Strike cLtp pLtp cSellOi pSellOi OiSell OiSB
5 12:13 19653 19600 99 49 851500 2530350 1678850 1917400
3 12:13 19653 19500 174 24 267500 1615600 1348100 390850
13 12:10 19645 19500 167 24 379050 1656000 1276950 301150
23 12:07 19640 19500 167 25 382350 1606500 1224150 257200
35 12:05 19629 19600 91 51 1324350 2542100 1217750 1525100
33 12:05 19629 19500 165 24 389700 1598450 1208750 278600
43 12:01 19625 19500 161 26 438850 1646950 1208100 183500
15 12:10 19645 19600 93 50 1318250 2519050 1200800 1249550
25 12:07 19640 19600 93 51 1365900 2544450 1178550 1307150
53 10:28 19614 19500 160 29 449000 1488200 1039200 141750
73 10:21 19616 19500 162 29 433200 1460400 1027200 229400
83 10:21 19616 19500 162 29 433200 1460400 1027200 229400
45 12:01 19625 19600 89 53 1594200 2599650 1005450 995200
4 12:13 19653 19550 135 34 268600 1263450 994850 777050
63 10:25 19615 19500 159 29 451850 1421650 969800 32650
103 10:18 19622 19500 159 29 454600 1413850 959250 94150
ERROR:
RuntimeError:
Expected x and y to reference fields in the supplied data source.
When a 'source' argument is passed to a glyph method, values that are sequences
(like lists or arrays) must come from references to data columns in the source.
For instance, as an example:
source = ColumnDataSource(data=dict(x=a_list, y=an_array))
p.circle(x='x', y='y', source=source, ...) # pass column names and a source
Alternatively, *all* data sequences may be provided as literals as long as a
source is *not* provided:
p.circle(x=a_list, y=an_array, ...) # pass actual sequences and no source