No (?) output from plotly.offline.iplot

I am trying to create a Sankey chart in a Jupyter notebook, basing my code on the first example shown here.

I ended up with this, which I can run without getting any errors:

import numpy as npy
import pandas as pd
import plotly as ply

ply.offline.init_notebook_mode(connected=True)

df = pd.read_csv('C:\\Users\\a245401\\Desktop\\Test.csv',sep=';')

print(df.head())
print(ply.__version__)

data_trace = dict(
    type='sankey',
    domain = dict(
      x =  [0,1],
      y =  [0,1]
    ),
    orientation = "h",
    valueformat = ".0f",
    node = dict(
      pad = 10,
      thickness = 30,
      line = dict(
        color = "black",
        width = 0.5
      ),
      label =  df['Node, Label'].dropna(axis=0, how='any'),
      color = df['Color']
    ),
    link = dict(
      source = df['Source'].dropna(axis=0, how='any'),
      target = df['Target'].dropna(axis=0, how='any'),
      value = df['Value'].dropna(axis=0, how='any'),
  )
)
print(data_trace)

layout =  dict(
    title = "Test",
    height = 772,
    width = 950,
    font = dict(
      size = 10
    ),    
)
print(layout)

fig = dict(data=[data_trace], layout=layout)
ply.offline.iplot(fig, filename='Test')

With the csv-file looking like this:

Source;Target;Value;Color;Node, Label
0;2;2958.5;#262C46;Test 1
0;2;236.7;#262C46;Test 2
0;2;1033.4;#262C46;Test 3
0;2;58.8;#262C46;Test 4
0;2;5.2;#262C46;Test 5
0;2;9.4;#262C46;Test 6
0;2;3.4;#262C46;Test 7

It seems to run fine, with the various outputs looking right at a first glance, but the final output from ply.offline.iplot(fig, filename='Test') just shows a large blank field:

Can someone please point me to where I am going wrong here?

I’ve also posted this question to StackOverflow.

I have the same issue myself with plotly 3.3. When I use plotly.plotly.iplot it works but what’s interesting is that plotly.offline.plot() works flawlessly!

Hi @cibic89,

Are you working in the classic jupyter notebook, JupyterLab, or something else? If you’re in the classic notebook then try updating it to the newest version of the notebook package. If you’re in JupyterLab you need to install the @jupyterlab/plotly-extension JupyterLab extension (follow the instructions at https://github.com/plotly/plotly.py#jupyterlab-support-python-35).

-Jon

1 Like

Hi jmmease,

I’m running jupyter lab and installed the extension and it works like a charm. Cheers for this!!

Thanks,
George

1 Like

@jmmease I am having the same issue with Plotly not showing figures offline lately. It appears to be happening intermittently.

I am using Jupyter notebook, Plotly v. 3.7.1, Jupyter v. 4.4.0, Python v. 2.7.1, and Anaconda v. 4.2.0.

I initialize offline mode by:

plotly.offline.init_notebook_mode(connected=True)

and plot my figures inline by:

plotly.offline.iplot(fig)

However, the last few days have been hit or miss with whether they plots actually show up inline or not - sometimes just a blank space. Just wondering if there may be a known reason for this? I have been using slower internet connections as I am working in a remote location in Canada at the moment, really the only thing I can think that of that has changed. Might this have something to do with it?

Hi @spencerchad,

If internet connectivity is questionable, I’d recommend setting connected=False in your call to init_notebook_mode. (or leave it out as False is the default). With connected=False, the Plotly.js bundle is directly embedded in the notebook, so no internet connection is required to fetch the Plotly.js library. The tradeoff is that this adds a couple of megabytes to the size of your notebook.

Hope that helps!
-Jon