Getting Started with Plot.ly

The graph(s) & code in this notebook are based on the overview/getting started guide for Plot.ly. It's a very nice plotting module for Python, with features you can't find in Matplotlib or Sympy.

https://plot.ly/python/overview/


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)


Figure(
    data=Data([
        Scatter(
            x=[1, 2, 3, 5, 6],
            y=[1, 4.5, 7, 24, 38],
            mode='markers'
        ),
        Scatter(
            x=[1, 2, 3, 5, 6],
            y=[1, 4, 9, 25, 36],
            mode='lines'
        )
    ]),
    layout=Layout(
        title='Fig 0.3: Some Experiment'
    )
)
Out[5]:

In [ ]: