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!
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
y0 = np.random.randn(50)-1
y1 = np.random.randn(50)+1
trace0 = go.Box(
y=y0
)
trace1 = go.Box(
y=y1
)
data = [trace0, trace1]
py.iplot(data)
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
x0 = np.random.randn(50)
x1 = np.random.randn(50) + 2
trace0 = go.Box(x=x0)
trace1 = go.Box(x=x1)
data = [trace0, trace1]
py.iplot(data)
import plotly.plotly as py
import plotly.graph_objs as go
data = [
go.Box(
y=[0, 1, 1, 2, 3, 5, 8, 13, 21],
boxpoints='all',
jitter=0.3,
pointpos=-1.8
)
]
py.iplot(data)
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
y0 = np.random.randn(50)
y1 = np.random.randn(50)+1
trace0 = go.Box(
y=y0,
name = 'Sample A',
marker = dict(
color = 'rgb(214, 12, 140)',
)
)
trace1 = go.Box(
y=y1,
name = 'Sample B',
marker = dict(
color = 'rgb(0, 128, 128)',
)
)
data = [trace0, trace1]
py.iplot(data)
import plotly.plotly as py
import plotly.graph_objs as go
trace0 = go.Box(
y=[2.37, 2.16, 4.82, 1.73, 1.04, 0.23, 1.32, 2.91, 0.11, 4.51, 0.51, 3.75, 1.35, 2.98, 4.50, 0.18, 4.66, 1.30, 2.06, 1.19],
name='Only Mean',
marker=dict(
color='rgb(8, 81, 156)',
),
boxmean=True
)
trace1 = go.Box(
y=[2.37, 2.16, 4.82, 1.73, 1.04, 0.23, 1.32, 2.91, 0.11, 4.51, 0.51, 3.75, 1.35, 2.98, 4.50, 0.18, 4.66, 1.30, 2.06, 1.19],
name='Mean & SD',
marker=dict(
color='rgb(10, 140, 208)',
),
boxmean='sd'
)
data = [trace0, trace1]
py.iplot(data)
import plotly.plotly as py
import plotly.graph_objs as go
trace0 = go.Box(
y = [0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25],
name = "All Points",
jitter = 0.3,
pointpos = -1.8,
boxpoints = 'all',
marker = dict(
color = 'rgb(7,40,89)'),
line = dict(
color = 'rgb(7,40,89)')
)
trace1 = go.Box(
y = [0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25],
name = "Only Whiskers",
boxpoints = False,
marker = dict(
color = 'rgb(9,56,125)'),
line = dict(
color = 'rgb(9,56,125)')
)
trace2 = go.Box(
y = [0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25],
name = "Suspected Outliers",
boxpoints = 'suspectedoutliers',
marker = dict(
color = 'rgb(8,81,156)',
outliercolor = 'rgba(219, 64, 82, 0.6)',
line = dict(
outliercolor = 'rgba(219, 64, 82, 0.6)',
outlierwidth = 2)),
line = dict(
color = 'rgb(8,81,156)')
)
trace3 = go.Box(
y = [0.75, 5.25, 5.5, 6, 6.2, 6.6, 6.80, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15,
8.15, 8.65, 8.93, 9.2, 9.5, 10, 10.25, 11.5, 12, 16, 20.90, 22.3, 23.25],
name = "Whiskers and Outliers",
boxpoints = 'outliers',
marker = dict(
color = 'rgb(107,174,214)'),
line = dict(
color = 'rgb(107,174,214)')
)
data = [trace0,trace1,trace2,trace3]
layout = go.Layout(
title = "Box Plot Styling Outliers"
)
fig = go.Figure(data=data,layout=layout)
py.iplot(fig, filename = "Box Plot Styling Outliers")
import plotly.plotly as py
import plotly.graph_objs as go
x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1',
'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']
trace0 = go.Box(
y=[0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3],
x=x,
name='kale',
marker=dict(
color='#3D9970'
)
)
trace1 = go.Box(
y=[0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],
x=x,
name='radishes',
marker=dict(
color='#FF4136'
)
)
trace2 = go.Box(
y=[0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5],
x=x,
name='carrots',
marker=dict(
color='#FF851B'
)
)
data = [trace0, trace1, trace2]
layout = go.Layout(
yaxis=dict(
title='normalized moisture',
zeroline=False
),
boxmode='group'
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
import plotly.plotly as py
import plotly.graph_objs as go
data = [
{
'x': [0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3],
'y': ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2'],
'name':'kale',
'marker': {
'color': '#3D9970'
},
'boxmean': False,
'orientation': 'h',
"type": "box",
},
{
'x': [0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],
'y': ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2'],
'name': 'radishes',
'marker':{
'color': '#FF4136',
},
'boxmean': False,
'orientation': 'h',
"type": "box",
},
{
'x': [0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5],
'y': ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2'],
'name':'carrots',
'marker': {
'color': '#FF851B',
},
'boxmean': False,
'orientation': 'h',
"type": "box",
}
]
layout = {
'xaxis': {
'title': 'normalized moisture',
'zeroline': False,
},
'boxmode': 'group',
}
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
import random
import plotly.plotly as py
from numpy import *
N = 30 # Number of boxes
# generate an array of rainbow colors by fixing the saturation and lightness of the HSL representation of colour
# and marching around the hue.
# Plotly accepts any CSS color format, see e.g. http://www.w3schools.com/cssref/css_colors_legal.asp.
c = ['hsl('+str(h)+',50%'+',50%)' for h in linspace(0, 360, N)]
# Each box is represented by a dict that contains the data, the type, and the colour.
# Use list comprehension to describe N boxes, each with a different colour and with different randomly generated data:
data = [{
'y': 3.5*sin(pi * i/N) + i/N+(1.5+0.5*cos(pi*i/N))*random.rand(10),
'type':'box',
'marker':{'color': c[i]}
} for i in range(int(N))]
# format the layout
layout = {'xaxis': {'showgrid':False,'zeroline':False, 'tickangle':60,'showticklabels':False},
'yaxis': {'zeroline':False,'gridcolor':'white'},
'paper_bgcolor': 'rgb(233,233,233)',
'plot_bgcolor': 'rgb(233,233,233)',
}
py.iplot(data)
import plotly.plotly as py
import plotly.graph_objs as go
x_data = ['Carmelo Anthony', 'Dwyane Wade',
'Deron Williams', 'Brook Lopez',
'Damian Lillard', 'David West',]
y0 = np.random.randn(50)-1
y1 = np.random.randn(50)+1
y2 = np.random.randn(50)
y3 = np.random.randn(50)+2
y4 = np.random.randn(50)-2
y5 = np.random.randn(50)+3
y_data = [y0,y1,y2,y3,y4,y5]
colors = ['rgba(93, 164, 214, 0.5)', 'rgba(255, 144, 14, 0.5)', 'rgba(44, 160, 101, 0.5)', 'rgba(255, 65, 54, 0.5)', 'rgba(207, 114, 255, 0.5)', 'rgba(127, 96, 0, 0.5)']
traces = []
for xd, yd, cls in zip(x_data, y_data, colors):
traces.append(go.Box(
y=yd,
name=xd,
boxpoints='all',
jitter=0.5,
whiskerwidth=0.2,
fillcolor=cls,
marker=dict(
size=2,
),
line=dict(width=1),
))
layout = go.Layout(
title='Points Scored by the Top 9 Scoring NBA Players in 2012',
yaxis=dict(
autorange=True,
showgrid=True,
zeroline=True,
dtick=5,
gridcolor='rgb(255, 255, 255)',
gridwidth=1,
zerolinecolor='rgb(255, 255, 255)',
zerolinewidth=2,
),
margin=dict(
l=40,
r=30,
b=80,
t=100,
),
paper_bgcolor='rgb(243, 243, 243)',
plot_bgcolor='rgb(243, 243, 243)',
showlegend=False
)
fig = go.Figure(data=traces, layout=layout)
py.iplot(fig)
Dash is an Open Source Python library which can help you convert plotly figures into a reactive, web-based application. Below is a simple example of a dashboard created using Dash. Its source code can easily be deployed to a PaaS.
from IPython.display import IFrame
IFrame(src= "https://dash-simple-apps.plotly.host/dash-boxplot/", width="100%", height="650px", frameBorder="0")
from IPython.display import IFrame
IFrame(src= "https://dash-simple-apps.plotly.host/dash-boxplot/code", width="100%", height=500, frameBorder="0")
See https://plotly.com/python/reference/#box for more information and chart 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(
'box.ipynb', 'python/box-plots/', 'Box Plots | plotly',
'How to make Box Plots in Python with Plotly.',
title = 'Box Plots | plotly',
name = 'Box Plots',
has_thumbnail='true', thumbnail='thumbnail/box.jpg',
language='python', page_type='example_index',
display_as='statistical', order=3,
ipynb='~notebook_demo/20')
Collecting git+https://github.com/plotly/publisher.git
Cloning https://github.com/plotly/publisher.git to /tmp/pip-req-build-65mlpoiq
Building wheels for collected packages: publisher
Running setup.py bdist_wheel for publisher ... done
Stored in directory: /tmp/pip-ephem-wheel-cache-sgtb8hkk/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966
Successfully built publisher
Installing collected packages: publisher
Found existing installation: publisher 0.13
Uninstalling publisher-0.13:
Successfully uninstalled publisher-0.13
Successfully installed publisher-0.13
You are using pip version 10.0.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.