4

I want to use the offline plotting of plotly inside a jupyter notebook and want to manipulate or redraw the plot by using widgets from ipywidgets. Unfortunately I do not manage to update the plots appropiately:

from ipywidgets import widgets, HBox, Output
import plotly as py
from plotly.offline import iplot
from IPython.display import display

%matplotlib inline
ip_widget = widgets.FloatSlider(
    value=6,
    min=3,
    max=10,
    step=1,
    description='num',
    continuous_update = True
)

ow = Output()
def response(change):
    with ow:
        iplot([{'x':list(range(int(ip_widget.value))), 'y': list(range(int(ip_widget.value)))}])
ip_widget.observe(response)
display(ip_widget)

The provided code has two disadvantages: It plots the graph multiple times. The graph only shows up, if the slider is used. How can I overcome these two issues? Please note that I don't want to use the online plotting capabilities of plotly and I don't want to solve this problem using interact.

Thank you very much for your answers.

1 Answer 1

4

Have you tried using interact? Here is a very clear example: http://nbviewer.jupyter.org/github/yankev/test/blob/master/plotlywidget_working2.ipynb

By the way, the interact function lives in ipywidgets (and not IPython.html.widgets anymore). Other than that, the example is pretty much up-to-date.

Sign up to request clarification or add additional context in comments.

Comments

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.