1

I'd like to draw interactive plot and dropdown winget. For this aim I use the following code in my jupyter notebook:

import ipywidgets as widgets
import plotly.graph_objects as go
import pandas as pd

df = pd.DataFrame({'timestamp' : [1,2,3,4,5,6], 'close' : [11,22,33,44,55,66], 'open' : [111,222,333,444,555,666]})

def plot(feature):
    fig = go.Figure(data=go.Scatter(x = df['timestamp'].values, y = df[feature].values),
        layout_title_text = feature
    )
    fig.show()

_ = widgets.interact(plot, feature = ['close', 'open'])

Every time when I select value in dropdown box the corresponding plot is displayed in separate output - but I'd like to update existing:

enter image description here

PLease explain how to fix this issue

Roman Kazmin
  • 931
  • 6
  • 18
  • Your code doesn't do that everywhere. I do find though I have to select something from the dropdown first. The same thing happens with the code [here](https://stackoverflow.com/a/73918907/8508004). For a place where it shows up only once, go [here](https://github.com/fomightez/3Dscatter_plot-binder) and click on '`launch binder`' badge. When the session spins up you can try your code there. There's an alternative all plotly way to do similar things that seems to work smoother, see [here](https://stackoverflow.com/a/71709798/8508004) or [here](https://stackoverflow.com/q/71296687/8508004). – Wayne Jan 27 '23 at 05:10
  • I added a related pure Plotly example to [here](https://stackoverflow.com/a/75366661/8508004). There's also a variation combining Plotly and ipywidgets to toggle what data to shown [there](https://stackoverflow.com/a/75366661/8508004), too. – Wayne Feb 07 '23 at 21:20

0 Answers0