Plotly Library Do Not Showed Anything

I tried to plot a scatter plot using plotly libraries.

import chart_studio.plotly as py
import plotly.offline as pyoff
import plotly.graph_objs as go

#plot monthly sales
plot_data = [
    go.Scatter(
        x=df['date'],
        y=df['qty'],
    )
]

plot_layout = go.Layout(
        title='Montly Sold'
    )
fig = go.Figure(data=plot_data, layout=plot_layout)
pyoff.iplot(fig)
fig.show()

The output is just a blank

How to overcome this problem?

1 Answer

I don't have the chart_studio installed but it seems it wasn't used anyway in your code. So after commenting chart_studio import and adding some data to your dataframe I can successfully run your code in my IDE (Eclipse). However it was opening two windows with the same plot so I had to remove one of the two last lines so just one window opens.

Then I tried your code in local Jupyter Notebook and in hosted Google CoLab and it works fine with the following code:

import plotly.graph_objs as go
import pandas as pd
import numpy as np

rng = pd.date_range('2015-02-24', periods=5, freq='T')
df = pd.DataFrame({ 'date': rng, 'qty': np.random.randn(len(rng)) }) 

#plot monthly sales
plot_data = [
    go.Scatter(
        x=df['date'],
        y=df['qty'],
    )
]

plot_layout = go.Layout(
        title='Montly Sold'
    )
fig = go.Figure(data=plot_data, layout=plot_layout)
fig.show()

Or you could leave the import plotly.offline as pyoff and use pyoff.iplot(fig) instead of fig.show() which also works fine.

Note: Running your code in Jupyter Notebook for the first time after (re-)starting you computer can take quite some time to generate and show a plot.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest