Update plot when dataframe changes

Hi everyone,

I would like to know how to update a given plot generated by:

df.hvplot(x="x", y="y", by="type", kind="scatter")

if I change the definition of df

Actually, I want to integrate it within the render method of stable_baselines3 custom-environment to see the progress of my learning - I want to visualize my agents position! So far, I have seen some examples that use streamz but could make it to work for my case.

In general, how would we update the data behind a given plot?


A way to do this is using bind and interactive (even though I’m using a fraction of its power)

import hvplot.pandas  # noqa
import pandas as pd
import panel as pn


def function_to_generate_dataframe(x):
    # x only used to trigger the function
    df = pd._testing.makeDataFrame()
    df["C"] = df["C"].round()
    return df

widget = pn.widgets.IntSlider(end=100)
hvplot.bind(function_to_generate_dataframe, widget).interactive().hvplot.scatter(x="A", y="B", by="C")

Thanks for the response. That looks like a very concise code.

I see that you can bind it to a widget. But how could we bind it to a function call (or maybe a Button widget?)?
E.g., whenever a function is called, a given plot (already in the Jupyter Notebook/dashboard) gets updated … using matplotlib, I guess we do it using the ax of the figure!

Thank you for bearing with my naivity.