Plotly - Plotting Inline with Jupyter Notebook



In this chapter, we will study how to do inline plotting with the Jupyter Notebook.

In order to display the plot inside the notebook, you need to initiate plotly’s notebook mode as follows −

from plotly.offline import init_notebook_mode
init_notebook_mode(connected = True)

Keep rest of the script as it is and run the notebook cell by pressing Shift+Enter. Graph will be displayed offline inside the notebook itself.

import plotly
plotly.tools.set_credentials_file(username = 'lathkar', api_key = '************')
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode(connected = True)

import plotly
import plotly.graph_objs as go
import numpy as np
import math #needed for definition of pi

xpoints = np.arange(0, math.pi*2, 0.05)
ypoints = np.sin(xpoints)
trace0 = go.Scatter(
   x = xpoints, y = ypoints
)
data = [trace0]
plotly.offline.iplot({ "data": data,"layout": go.Layout(title="Sine wave")})

Jupyter notebook output will be as shown below −

Jupyter Notebook

The plot output shows a tool bar at top right. It contains buttons for download as png, zoom in and out, box and lasso, select and hover.

Tool Bar
Advertisements