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

2
  • 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. For a place where it shows up only once, go here 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 or here. Commented Jan 27, 2023 at 5:10
  • I added a related pure Plotly example to here. There's also a variation combining Plotly and ipywidgets to toggle what data to shown there, too. Commented Feb 7, 2023 at 21:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.