2

i'm just trying out plotly/dash and when i write the below code nothing gets displayed.. it's just a blank box. I've tried installing nodejs (i'm using anaconda) so that i can try and install some extension ' jupyter labextension install @jupyterlab/plotly-extension' but this does not work for some reason i cannot even install nodejs.

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.offline as pyo
import plotly.graph_objs as go
# Set notebook mode to work in offline
pyo.init_notebook_mode()
#init_notebook_mode(connected=True)
# Create traces
trace0 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[10, 15, 13, 17]
)
trace1 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[16, 5, 11, 9]
)
# Fill out data with our traces
data = [trace0, trace1]
layout=go.Layout(barmode='stack')
fig=go.Figure(data=data, layout=layout)
# Plot it and save as basic-line.html
pyo.iplot(fig, filename = 'basic-line')

what else can i do to help view my graph?

4
  • iplot() could be the problem. Commented Oct 4, 2019 at 11:36
  • Did you install the plotly extension? And why can't you install nodejs? Commented Oct 4, 2019 at 11:45
  • @vestland i was unable to install the extension. I could not install nodejs as it says it is corrupted in my pkgs folders for anaconda. Commented Oct 4, 2019 at 12:45
  • i have also updated my jupyter notebook yet nothing Commented Oct 4, 2019 at 12:57

3 Answers 3

2

I'd like some more info regarding versions of plolty, Jupyterlab etc, but iplot() could very likely be the problem here. Try another basic example like:

Code:

import plotly.graph_objects as go
animals=['giraffes', 'orangutans', 'monkeys']

fig = go.Figure(data=[
    go.Bar(name='SF Zoo', x=animals, y=[20, 14, 23]),
    go.Bar(name='LA Zoo', x=animals, y=[12, 18, 29])
])
# Change the bar mode
fig.update_layout(barmode='stack')
fig.show()

Plot:

enter image description here

Let me know how that worked out for you.

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

2 Comments

hi this doesn't work - it's just blank :/ . i'm on jupyter notebook and plotly version '4.1.1'
i have been reading some forums and the above only works if i but fig.show(renderer="svg") @vestland however i do not know how to get iplot working
1

When you run your code and the browser pops up, click in the address bar and hit enter.

Comments

0

You can try this Google Colab have given instruction regrading Plotly

def configure_plotly_browser_state():
  import IPython
  display(IPython.core.display.HTML('''
        <script src="/static/components/requirejs/require.js"></script>
        <script>
          requirejs.config({
            paths: {
              base: '/static/base',
              plotly: 'https://cdn.plot.ly/plotly-1.5.1.min.js?noext',
            },
          });
        </script>
        '''))

Call this function configure_plotly_browser_state()

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.