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.3.0'
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
x = np.random.uniform(-1, 1, size=500)
y = np.random.uniform(-1, 1, size=500)
trace = [go.Histogram2dContour(
x = x,
y = y
)]
py.iplot(trace, filename = "Basic Histogram2dContour")
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
x = np.random.uniform(-1, 1, size=500)
y = np.random.uniform(-1, 1, size=500)
trace = [go.Histogram2dContour(
x = x,
y = y,
colorscale = 'Blues'
)]
py.iplot(trace, filename = "Histogram2dContour Colorscale")
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
x = np.random.uniform(-1, 1, size=500)
y = np.random.uniform(-1, 1, size=500)
trace = [go.Histogram2dContour(
x = x,
y = y,
colorscale = 'Jet',
contours = dict(
showlabels = True,
labelfont = dict(
family = 'Raleway',
color = 'white'
)
),
hoverlabel = dict(
bgcolor = 'white',
bordercolor = 'black',
font = dict(
family = 'Raleway',
color = 'black'
)
)
)]
py.iplot(trace, filename = "Histogram2dContour Styled")
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
t = np.linspace(-1, 1.2, 2000)
x = (t**3) + (0.3 * np.random.randn(2000))
y = (t**6) + (0.3 * np.random.randn(2000))
data = [
go.Histogram2dContour(
x = x,
y = y,
colorscale = 'Blues',
reversescale = True,
xaxis = 'x',
yaxis = 'y'
),
go.Scatter(
x = x,
y = y,
xaxis = 'x',
yaxis = 'y',
mode = 'markers',
marker = dict(
color = 'rgba(0,0,0,0.3)',
size = 3
)
),
go.Histogram(
y = y,
xaxis = 'x2',
marker = dict(
color = 'rgba(0,0,0,1)'
)
),
go.Histogram(
x = x,
yaxis = 'y2',
marker = dict(
color = 'rgba(0,0,0,1)'
)
)
]
layout = go.Layout(
autosize = False,
xaxis = dict(
zeroline = False,
domain = [0,0.85],
showgrid = False
),
yaxis = dict(
zeroline = False,
domain = [0,0.85],
showgrid = False
),
xaxis2 = dict(
zeroline = False,
domain = [0.85,1],
showgrid = False
),
yaxis2 = dict(
zeroline = False,
domain = [0.85,1],
showgrid = False
),
height = 600,
width = 600,
bargap = 0,
hovermode = 'closest',
showlegend = False
)
fig = go.Figure(data=data,layout=layout)
py.iplot(fig, filename='Histogram2dContour Subplot')
See https://plotly.com/python/reference/#histogram2dcontour 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(
'histogram2dcontour.ipynb', 'python/2d-histogram-contour/', '2D Histogram Contour',
'How to make 2D Histogram Contour plots in Python with Plotly.',
title = '2D Histogram Contour | Plotly',
has_thumbnail='true', thumbnail='thumbnail/hist2dcontour.png',
language='python',
# page_type='example_index', // note this is only if you want the tutorial to appear on the main page: plot.ly/python
display_as='statistical',
order=30,
ipynb='~notebook_demo/199',
uses_plotly_offline=False)
Collecting git+https://github.com/plotly/publisher.git Cloning https://github.com/plotly/publisher.git to c:\users\branden\appdata\local\temp\pip-99s09b37-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: started Running setup.py install for publisher: finished with status 'done' Successfully installed publisher-0.11
C:\Users\Branden\Anaconda3\envs\ipykernel_py2\lib\site-packages\IPython\nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead. C:\Users\Branden\Anaconda3\envs\ipykernel_py2\lib\site-packages\publisher\publisher.py:53: UserWarning: Did you "Save" this notebook before running this command? Remember to save, always save.