Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!
Plotly's python package is updated frequently. Run pip install plotly --upgrade
to use the latest version.
import plotly
plotly.__version__
'3.1.1'
import plotly.plotly as py
import plotly.graph_objs as go
trace1 = go.Scatter(
x=[1, 2, 3, 4],
y=[0, 2, 3, 5],
fill='tozeroy'
)
trace2 = go.Scatter(
x=[1, 2, 3, 4],
y=[3, 5, 1, 7],
fill='tonexty'
)
data = [trace1, trace2]
py.iplot(data, filename='basic-area')
import plotly.plotly as py
import plotly.graph_objs as go
trace1 = go.Scatter(
x=[1, 2, 3, 4],
y=[0, 2, 3, 5],
fill='tozeroy',
mode= 'none'
)
trace2 = go.Scatter(
x=[1, 2, 3, 4],
y=[3, 5, 1, 7],
fill='tonexty',
mode= 'none'
)
data = [trace1, trace2]
py.iplot(data, filename='basic-area-no-bound')
import plotly.plotly as py
import plotly.graph_objs as go
trace0 = go.Scatter(
x=[1, 2, 3, 4],
y=[3, 4, 8, 3],
fill= None,
mode='lines',
line=dict(
color='rgb(143, 19, 131)',
)
)
trace1 = go.Scatter(
x=[1, 2, 3, 4],
y=[1, 6, 2, 6],
fill='tonexty',
mode='lines',
line=dict(
color='rgb(143, 19, 131)',
)
)
data = [trace0, trace1]
py.iplot(data, filename='filling-interior-area')
import plotly.plotly as py
import plotly.graph_objs as go
# Add original data
x=['Winter', 'Spring', 'Summer', 'Fall']
trace0 = dict(
x=x,
y=[40, 60, 40, 10],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5,
color='rgb(131, 90, 241)'),
stackgroup='one'
)
trace1 = dict(
x=x,
y=[20, 10, 10, 60],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5,
color='rgb(111, 231, 219)'),
stackgroup='one'
)
trace2 = dict(
x=x,
y=[40, 30, 50, 30],
hoverinfo='x+y',
mode='lines',
line=dict(width=0.5,
color='rgb(184, 247, 212)'),
stackgroup='one'
)
data = [trace0, trace1, trace2]
fig = dict(data=data)
py.iplot(fig, filename='stacked-area-plot-hover', validate=False)
import plotly.plotly as py
import plotly.graph_objs as go
trace0 = dict(
x=['Winter', 'Spring', 'Summer', 'Fall'],
y=['40', '20', '30', '40'],
mode='lines',
line=dict(width=0.5,
color='rgb(184, 247, 212)'),
stackgroup='one',
groupnorm='percent'
)
trace1 = dict(
x=['Winter', 'Spring', 'Summer', 'Fall'],
y=['50', '70', '40', '60'],
mode='lines',
line=dict(width=0.5,
color='rgb(111, 231, 219)'),
stackgroup='one'
)
trace2 = dict(
x=['Winter', 'Spring', 'Summer', 'Fall'],
y=['70', '80', '60', '70'],
mode='lines',
line=dict(width=0.5,
color='rgb(127, 166, 238)'),
stackgroup='one'
)
trace3 = dict(
x=['Winter', 'Spring', 'Summer', 'Fall'],
y=['100', '100', '100', '100'],
mode='lines',
line=dict(width=0.5,
color='rgb(131, 90, 241)'),
stackgroup='one'
)
data = [trace0, trace1, trace2, trace3]
layout = go.Layout(
showlegend=True,
xaxis=dict(
type='category',
),
yaxis=dict(
type='linear',
range=[1, 100],
dtick=20,
ticksuffix='%'
)
)
fig = dict(data=data, layout=layout)
py.iplot(fig, filename='stacked-area-plot-norm', validate=False)
import plotly.plotly as py
import plotly.graph_objs as go
trace0 = go.Scatter(
x=[0,0.5,1,1.5,2],
y=[0,1,2,1,0],
fill= 'toself',
fillcolor = '#ab63fa',
hoveron = 'points+fills',
line = dict(
color = '#ab63fa'
),
text = "Points + Fills",
hoverinfo = 'text'
)
trace1 = go.Scatter(
x=[3,3.5,4,4.5,5],
y=[0,1,2,1,0],
fill='toself',
fillcolor = '#e763fa',
hoveron = 'points',
line = dict(
color = '#e763fa'
),
text = "Points only",
hoverinfo = 'text'
)
data = [trace0, trace1]
layout = go.Layout(
title = "hover on <i>points</i> or <i>fill</i>",
xaxis = dict(
range = [0,5.2]
),
yaxis = dict(
range = [0,3]
)
)
fig = go.Figure(data=data,layout=layout)
py.iplot(data, filename='select-hover-points')
See https://plotly.com/python/reference/#scatter-line and https://plotly.com/python/reference/#scatter-fill for more information and attribute options!
from IPython.display import display, HTML
display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))
! pip install git+https://github.com/plotly/publisher.git --upgrade
import publisher
publisher.publish(
'area.ipynb', 'python/filled-area-plots/', 'Filled Area Plots | plotly',
'How to make filled area plots in Python with Plotly.',
title = 'Filled Area Plots | plotly',
name = 'Filled Area Plots',
thumbnail='thumbnail/area.jpg', language='python',
has_thumbnail='true', display_as='basic', order=3.5,
ipynb='~notebook_demo/8')
Collecting git+https://github.com/plotly/publisher.git
Cloning https://github.com/plotly/publisher.git to /tmp/pip-req-build-ewWF0_
Building wheels for collected packages: publisher
Running setup.py bdist_wheel for publisher ... done
Stored in directory: /tmp/pip-ephem-wheel-cache-zaYWOc/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966
Successfully built publisher
Installing collected packages: publisher
Found existing installation: publisher 0.11
Uninstalling publisher-0.11:
Successfully uninstalled publisher-0.11
Successfully installed publisher-0.11
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.