I have not resolved this yet, but am again interested in finding a solution.
I advanced a tiny bit and slightly changed the MWE
import random
import asyncio
from functools import partial
import pandas as pd
import holoviews as hv
import bokeh
hv.extension('bokeh')
import panel as pn
from holoviews.streams import Buffer
def make_df(x=0.0, y=0.0, z=0.0):
return pd.DataFrame(data={'x': x, 'y': y, 'z': z}, index=[0])
empty_df = pd.DataFrame(columns=make_df().columns)
buffer_length = 1000
buffer = Buffer(empty_df, length=buffer_length, index=False)
plot = hv.DynamicMap(partial(hv.Curve, kdims='x', vdims=['y', 'z']), streams=[buffer]).opts(
#color='z'#this never works with curve, should use "groupby" instead, but how?
)
scatterplot = hv.DynamicMap(partial(hv.Scatter, kdims='x', vdims=['y', 'z']), streams=[buffer]).opts(
color = 'k',#changing this to 'z' makes the markers disappear
marker='o',
size=5
)
LABEL_START = 'Start'
LABEL_STOP = 'Stop'
button_run = pn.widgets.Button(name=LABEL_START)
button_reset_all_plots = pn.widgets.Button(name='Reset')
task = None
def reset_all_plots(self):
buffer.clear()
button_reset_all_plots.on_click(reset_all_plots)
async def focus():
seed = random.random()
for i in range(10):
datapoint_x = i
datapoint_y = datapoint_x * seed
datapoint_z = float(i)
datum = make_df(datapoint_x, datapoint_y, datapoint_z)
buffer.send(datum)
await asyncio.sleep(0.1)
button_run.name = LABEL_START
return
def run_focus(events):
global task
if button_run.name is LABEL_START:
button_run.name = LABEL_STOP
task = asyncio.gather(focus())
else:
task.cancel()
button_run.name = LABEL_START
button_run.on_click(run_focus)
plots = pn.Column(plot*scatterplot, pn.Row(button_reset_all_plots, button_run))
plots
I added an additional vdim
, and use that to color the hv.Scatter
plot. But this only works when i call hv.Scatter
directly for example after generating data using the button in the MWE
hv.Scatter(scatterplot.dframe(), kdims='x', vdims=['y','z']).opts(color='z')
I don’t know how to pass the option to hv.Scatter
inside the hv.DynamicMap
.
Also, trying the same with hv.Curve
instead of hv.Scatter
does not work at all. The error message says I should use groupby
instead, but I don’t understand how.
not sure if this were easier if the partial
wasn’t there, but as far as I know I need it to specify which columns I want to plot of a larger dataframe (see here)