Plotly: beautiful graph-building tool

Found this super powerful graphing tool by chance. It satisfies a few key demands:

  1. It builds interative beautiful plots.
  2. It can output as html or embeddable html code.
  3. It also offer a online mode to view plots through a dashboard and to embed plots through its api, if data safety is not a big concern.

Ref:

Below are some small example usage…

I. juhpyter notebook inline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import plotly
import plotly.offline as py
from plotly import graph_objs as go
import numpy as np

py.init_notebook_mode(connected=True)

# Simple sine function
x = np.linspace(0,2*np.pi)
y = np.sin(x)
trace = go.Scatter(x=x,y=y)
layout = go.Layout(title = 'title goes here')
fig = go.Figure(data = [trace], layout = layout)
py.iplot(fig)
II. output as html
1
2
3
4
5
6
7
8
9
import  plotly
import plotly.graph_objs as go
import plotly.plotly as py


plotly.offline.plot({
"data": [go.Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])],
"layout": go.Layout(title="hello world")
})
III. aquire embeddable html code

*for example page, check “Plotly: show page.html”

*to embed, must include .js link in the head of the html

1
2
3
4
5
6
7
8
import  plotly
import plotly.graph_objs as go

data = [{"x": [1, 2, 3], "y": [3, 1, 6]}]
layout = go.Layout(
title='Simple example')
fig = go.Figure(data=data, layout=layout)
plotly.offline.plot(fig, include_plotlyjs=False, output_type='div')
0%