It is a plotting library made for python for making interactive plots in python displayed in html files.
Install plotly using pip
.
pip install plotly
You can also use conda
as well.
conda install -c conda-forge plotly
Plotly has two variants:
Both of them are used for making plots. The difference is that the offline version does not the data to be stored in the plotly account.
# Imports
import numpy as np
import plotly.graph_objs as go
import plotly.offline as ply
# Sample data to plot
= 201
n = np.linspace(0, 2.0*np.pi, n)
x = np.sin(x)
y1 = np.cos(x)
y2 = y1 + y2
y3
## Plotly steps begin.
### Step 1: Create Traces
= go.Scatter(
trace1 = x,
x = y1,
y = "sine curve",
name = dict(
line = ("green"),
color = 4,
width = 'dot'
dash
)
)
= go.Scatter(
trace2 = x,
x = y2,
y = "cosine curve",
name = dict(
line = ("red"),
color = 4,
width = 'dash'
dash
)
)
= go.Scatter(
trace3 = x,
x = y3,
y = "sine + cosine curve",
name = dict(
line = ("blue"),
color = 4,
width = 'dashdot'
dash
)
)
### Step 2: Create information / layout dictionary
= dict(
layout = "Sine Curves",
title = dict(title = "Angle in Radian"),
xaxis = dict(title = "Angle in Radian")
yaxis
)
### Pack all the traces to get a data list
= [trace1, trace2, trace3]
data
### Create a figure dictionary
= dict(data = data, layout = layout)
fig
### Plot the figure in a html file
="plotly_test1.html") ply.plot(data, filename