EJSuh
EJSuh

Reputation: 325

Showing plotly on jupyter notebook

I have a dataframe 'country' that I am plotting using jupyter notebook.

It plotted nicely on Kaggle's notebook, but refuses to show when I use jupyter notebook..

I've read similar problems on StackOverflow, and I've tried both :

init_notebook_mode(connected=True)

&

py.offline.init_notebook_mode(connected=True)

Please find the full code below:

import plotly.offline as py
from plotly.offline import iplot
py.offline.init_notebook_mode(connected=True)
import plotly.graph_objs as go

trace1 = go.Bar(
    x= country.index,
    y= country['Avg. Points'],
    name='Avg. Points'
)

trace2= go.Bar(
    x= country.index,
    y= country['Avg. Price'],
    name='Avg. Price'
)

data=[trace1, trace2]
layout=go.Layout(
    barmode='stack')

fig=go.Figure(data=data, layout=layout)
py.iplot(fig, filename='stacked-bar')

The below image is how it looks on Kaggle.enter image description here

Upvotes: 3

Views: 8060

Answers (1)

Josmoor98
Josmoor98

Reputation: 1811

I tried using your code, replacing your data with some of Plotly's example data. I'm not able to replicate the issue you're having. Assuming you have correctly installed plotly using $ pip install plotly and there are no issues with the data, the following should work.

from plotly.offline import iplot isn't necessary, since you use py.iplot.

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

py.init_notebook_mode(connected=True)

trace1 = go.Bar(
    x= country.index,
    y= country['Avg. Points'],
    name='Avg. Points'
)

trace2= go.Bar(
    x= country.index,
    y= country['Avg. Price'],
    name='Avg. Price'
)

data=[trace1, trace2]
layout=go.Layout(barmode='stack')

fig=go.Figure(data=data, layout=layout)
py.iplot(fig, filename='stacked-bar')

Upvotes: 3

Related Questions