In [5]:
import plotly.plotly as py
from plotly.graph_objs import Data, Figure, Layout, Scatter
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
# Configure Plotly to work locally, rather than saving all plots
# remotely, in my Plot.ly account, through Plot.ly's API.
init_notebook_mode()
# Make three lists of numbers
x = [1, 2, 3, 5, 6]
y1 = [1, 4.5, 7, 24, 38]
y2 = [1, 4, 9, 25, 36]
# (1.1) Make a 1st Scatter object
trace1 = Scatter(
x=x, # x-coordinates of trace
y=y1, # y-coordinates of trace
mode='markers' # scatter mode (more in UG section 1)
)
# (1.2) Make a 2nd Scatter object
trace2 = Scatter(
x=x, # same x-coordinates
y=y2, # different y-coordinates
mode='lines' # different scatter mode
)
# (2) Make Data object
data = Data([trace1, trace2]) # (!) Data is list-like, must use [ ]
# (3) Make Layout object (Layout is dict-like)
layout = Layout(title='Fig 0.3: Some Experiment')
# (4) Make Figure object (Figure is dict-like)
fig = Figure(data=data, layout=layout)
# Display pretty-printed dump of the Figure's data
print(fig.to_string())
py.iplot(fig)
Out[5]:
In [ ]: