Filipe Ferminiano
Filipe Ferminiano

Reputation: 8791

Unable to show chart with plotly

I'm trying to run this example:

import plotly
plotly.__version__

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

from plotly.offline import download_plotlyjs, init_notebook_mode, plot,iplot


# Create random data with numpy
import numpy as np

N = 500
random_x = np.linspace(0, 1, N)
random_y = np.random.randn(N)

# Create a trace
trace = go.Scatter(
    x = random_x,
    y = random_y
)

data = [trace]

iplot(data, filename='basic-line')

But the last line iplot... is opening iPython and not showing the chart. How can I fix this?

Upvotes: 0

Views: 346

Answers (1)

Naren Murali
Naren Murali

Reputation: 56650

You missed the line

plotly.offline.init_notebook_mode()

Code:

import plotly
plotly.__version__

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

from plotly.offline import download_plotlyjs, init_notebook_mode, plot,iplot
plotly.offline.init_notebook_mode()

# Create random data with numpy
import numpy as np

N = 500
random_x = np.linspace(0, 1, N)
random_y = np.random.randn(N)

# Create a trace
trace = go.Scatter(
    x = random_x,
    y = random_y
)

data = [trace]

iplot(data, filename='basic-line')

Upvotes: 2

Related Questions