7

I need to plot my data using plotly, But this code doesn't give me any result, I display my data, but without any figure:

    import plotly.graph_objs as go
    from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

    data_t = []

    for mac, dico_data in dict_info.items():
        data_t.append(go.Scatter( x= dico_data['asn'], y= dico_data["time"], name=mac ))
        print (data_t)
    data = data_t
    iplot(data_t)
4
  • 1
    have you run this in a Jupyter notebook? It seems plotly scripts need to be run in a Jupyter notebook. note: Use plotly.offline.iplot() when working offline in a Jupyter Notebook to display the plot in the notebook., src: plot.ly/python/getting-started/… Commented Oct 23, 2018 at 19:26
  • Yes I try offline.plot(data_t) and it works. Commented Oct 23, 2018 at 19:30
  • Welcome to SO! If any of the answers helped solved your question, it would be beneficial if you close your question by accepting the best answer Commented Oct 23, 2018 at 19:36
  • If you add in Plotly's orca now you can generate a static image of the plot that doesn't require being in a notebook to then see. All can be done without using notebooks, see my comment below Neeraj Vashistha's answer here. (You'll note that I am only really using Jupyter there to have a remote server that has orca installed to enable demonstration.) See here about orca. Commented Jun 4, 2019 at 20:33

2 Answers 2

8

Try using:

init_notebook_mode(connected=True)

Or try using the inline mode in notebooks:

py.init_notebook_mode()

And if you are using it out of a notebook, try the following example:

import plotly
import plotly.graph_objs as go

plotly.offline.plot({
    "data": [go.Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])],
    "layout": go.Layout(title="hello world")
}, auto_open=True)

Read more in the plotly documentation: https://plot.ly/python/offline/

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

2 Comments

It doen't give me any result, figure doesn't appear
Can you try my added solution?
1

Issue: Due to inbuilt restriction in browser, you need to install

plotly-extension

Solution: Install it if missing with:

jupyter labextension install @jupyterlab/plotly-extension

Reference:

  1. https://jupyterlab.readthedocs.io/en/stable/user/extensions.html

Comments

Your Answer

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