I am using the following MWE to simulate plotting data from an experiment.
When I stop and restart, I want the next curve (or points) to be colored differently.
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):
return pd.DataFrame(data={'x': x, 'y': y}, 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'), streams=[buffer]).opts(
#color=hv.Cycle('Spectral'),
#color=hv.Palette('Spectral'),
#color=hv.dim('???'),
)
scatterplot = hv.DynamicMap(partial(hv.Scatter, kdims='x', vdims='y'), streams=[buffer]).opts(
color = 'k',
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
datum = make_df(datapoint_x, datapoint_y)
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
Using hv.cycle
or hv.palette
changes the color, but only initially, not upon each new run, since I am technically still plotting the same hv.curve
. I don’t understand how to use hv.dim()
+some dummy variable.
Any help would be appreciated