ebuzz168
ebuzz168

Reputation: 1194

Plotly Library do not showed anything

I tried to plot a scatter plot using plotly libraries.

enter image description here

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 enter image description here

How to overcome this problem?

Upvotes: 1

Views: 1465

Answers (1)

Tony
Tony

Reputation: 8297

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.

enter image description here enter image description here

Upvotes: 3

Related Questions