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__
'2.2.1'
import plotly.offline as off
import pandas as pd
off.init_notebook_mode(connected=False)
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")
colors = ['blue', 'orange', 'green', 'red', 'purple']
opt = []
opts = []
for i in range(0, len(colors)):
opt = dict(
target = df['continent'][[i]].unique(), value = dict(marker = dict(color = colors[i]))
)
opts.append(opt)
data = [dict(
type = 'scatter',
mode = 'markers',
x = df['lifeExp'],
y = df['gdpPercap'],
text = df['continent'],
hoverinfo = 'text',
opacity = 0.8,
marker = dict(
size = df['pop'],
sizemode = 'area',
sizeref = 200000
),
transforms = [
dict(
type = 'filter',
target = df['year'],
orientation = '=',
value = 2007
),
dict(
type = 'groupby',
groups = df['continent'],
styles = opts
)]
)]
layout = dict(
yaxis = dict(
type = 'log'
)
)
off.iplot({'data': data, 'layout': layout}, validate=False)
import plotly.offline as off
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")
data = [dict(
type = 'scatter',
mode = 'markers',
x = df['lifeExp'],
y = df['gdpPercap'],
text = df['continent'],
hoverinfo = 'text',
opacity = 0.8,
marker = dict(
size = df['pop'],
sizemode = 'area',
sizeref = 200000
),
transforms = [
dict(
type = 'filter',
target = df['year'],
orientation = '=',
value = 2007
),
dict(
type = 'aggregate',
groups = df['continent'],
aggregations = [
dict(target = 'x', func = 'avg'),
dict(target = 'y', func = 'avg'),
dict(target = 'marker.size', func = 'sum')
]
)]
)]
layout = dict(
yaxis = dict(
type = 'log'
)
)
off.iplot({'data': data, 'layout': layout}, validate=False)
import plotly.offline as off
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")
colors = ['blue', 'orange', 'green', 'red', 'purple']
opt = []
opts = []
for i in range(0, len(colors)):
opt = dict(
target = df['continent'][[i]].unique(), value = dict(marker = dict(color = colors[i]))
)
opts.append(opt)
data = [dict(
type = 'scatter',
mode = 'markers',
x = df['lifeExp'],
y = df['gdpPercap'],
text = df['continent'],
hoverinfo = 'text',
opacity = 0.8,
marker = dict(
size = df['pop'],
sizemode = 'area',
sizeref = 200000
),
transforms = [
dict(
type = 'filter',
target = df['year'],
orientation = '=',
value = 2007
),
dict(
type = 'groupby',
groups = df['continent'],
styles = opts
),
dict(
type = 'aggregate',
groups = df['continent'],
aggregations = [
dict(target = 'x', func = 'avg'),
dict(target = 'y', func = 'avg'),
dict(target = 'marker.size', func = 'sum')
]
)]
)]
layout = dict(
title = '<b>Gapminder</b><br>2007 Average GDP Per Cap & Life Exp. by Continent',
yaxis = dict(
type = 'log'
)
)
off.iplot({'data': data, 'layout': layout}, validate=False)
See https://plotly.com/python/reference/ 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(
'multiple-transforms.ipynb', 'python/multiple-transforms/', 'Multiple Transforms',
'How to use multiple transforms (filter, group by, and aggregates) in Python with Plotly.',
title = 'Multiple Transforms | Plotly',
has_thumbnail='true', thumbnail='thumbnail/multiple-transforms.jpg',
language='python', uses_plotly_offline=True,
page_type='example_index',
display_as='transforms', order=4,
ipynb= '~notebook_demo/193')
Collecting git+https://github.com/plotly/publisher.git Cloning https://github.com/plotly/publisher.git to /private/var/folders/k_/zf24qrfn2kg710j9pdrxzrz40000gn/T/pip-auzIFU-build Installing collected packages: publisher Found existing installation: publisher 0.11 Uninstalling publisher-0.11: Successfully uninstalled publisher-0.11 Running setup.py install for publisher ... done Successfully installed publisher-0.11
/Users/chelsea/venv/venv2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead. /Users/chelsea/venv/venv2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you "Save" this notebook before running this command? Remember to save, always save.