Black Lives Matter. Please consider donating to Black Girls Code today.

Offline iplots in plotly with python

Hi,

I’m new to ploytly. I’m experiencing some issues (blank plot) using offline plot options with plotly and python. I followed some suggestions as in https://community.plotly.com/t/offline-mode-in-jupyter-notebook-shows-blank-graphs/1860. but without sucess. My plotly version is 1.12.19 and my phyton version is 3.6.0.

I did some modifications in the Color Palette for Bar Chart example contained in https://plot.ly/python/horizontal-bar-charts/. My online plot works fine when I try :

 fig = go.Figure(data=traces, layout=layout)
 plotly.iplot(fig, filename='bar-colorscale')

However, if I try :

fig = go.Figure(data=traces, layout=layout)
plotly.offline.iplot(fig, filename='bar-colorscale')  

or
plotly.offline.plot(fig, filename='bar-colorscale')

The result is a blank plot, with plotly api and x and y axis :

I tried a simple test with plotly.offline.plot using :

trace = go.Bar(x=[2, 4, 6], y= [10, 12, 15])
data = [trace]
layout = go.Layout(title='A Simple Plot', width=800, height=640)
fig = go.Figure(data=data, layout=layout)
plotly.offline.plot(fig, filename='a-simple-plot') 

And it works perfectly. So I believe that the issue is in fig. In the Color Palette for Bar Chart example, fig has a list of traces (stacked bar). But in the test example above, trace is a single graphic object (go) element.

Is there a way to make a offline plot from a trace that contains many graphic objects (as showed in the Color Palette for Bar Chart example )? Or maybe I’m doing something else wrong ?

Thank you

Paulo

Hi there,
Could you include the code for the example that isn’t working for you (maybe I misunderstood but it looks like you just included the code that is working for you). Could you also see if this issue persists on an upgraded version of the API, we’re not currently on version 2.0.8.

I try to copy exactly the same code in the example and it is not working. i believe this is regardless offline or online plot. the guess the problem lie in the ‘traces’ assignment below:

for i in range(0, len(x_data[0])):
for xd, yd in zip(x_data, y_data):
traces.append(go.Bar(
x=xd[i],
y=yd,
orientation=‘h’,
marker=dict(
color=colors[i],
line=dict(
color=‘rgb(248, 248, 249)’,
width=1)
)
))