jupyter
jupytext
kernelspec
language_info
plotly
notebook_metadata_filter
text_representation
all
extension
format_name
format_version
jupytext_version
.md
markdown
1.1
1.1.1
display_name
language
name
Python 3
python
python3
codemirror_mode
file_extension
mimetype
name
nbconvert_exporter
pygments_lexer
version
.py
text/x-python
python
python
ipython3
3.6.7
description
display_as
has_thumbnail
ipynb
language
layout
name
order
page_type
permalink
thumbnail
title
How to make 2D Histogram Contour plots in Python with Plotly.
statistical
true
~notebook_demo/199
python
base
2D Histogram Contour
30
u-guide
python/2d-histogram-contour/
thumbnail/hist2dcontour.png
2D Histogram Contour | Plotly
Basic 2D Histogram Contour
import plotly .graph_objects as go
import numpy as np
np .random .seed (1 )
x = np .random .uniform (- 1 , 1 , size = 500 )
y = np .random .uniform (- 1 , 1 , size = 500 )
fig = go .Figure (go .Histogram2dContour (
x = x ,
y = y
))
fig .show ()
2D Histogram Contour Colorscale
import plotly .graph_objects as go
import numpy as np
x = np .random .uniform (- 1 , 1 , size = 500 )
y = np .random .uniform (- 1 , 1 , size = 500 )
fig = go .Figure (go .Histogram2dContour (
x = x ,
y = y ,
colorscale = 'Blues'
))
fig .show ()
2D Histogram Contour Styled
import plotly .graph_objects as go
import numpy as np
x = np .random .uniform (- 1 , 1 , size = 500 )
y = np .random .uniform (- 1 , 1 , size = 500 )
fig = go .Figure (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'
)
)
))
fig .show ()
2D Histogram Contour Subplot
import plotly .graph_objects 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 ))
fig = go .Figure ()
fig .add_trace (go .Histogram2dContour (
x = x ,
y = y ,
colorscale = 'Blues' ,
reversescale = True ,
xaxis = 'x' ,
yaxis = 'y'
))
fig .add_trace (go .Scatter (
x = x ,
y = y ,
xaxis = 'x' ,
yaxis = 'y' ,
mode = 'markers' ,
marker = dict (
color = 'rgba(0,0,0,0.3)' ,
size = 3
)
))
fig .add_trace (go .Histogram (
y = y ,
xaxis = 'x2' ,
marker = dict (
color = 'rgba(0,0,0,1)'
)
))
fig .add_trace (go .Histogram (
x = x ,
yaxis = 'y2' ,
marker = dict (
color = 'rgba(0,0,0,1)'
)
))
fig .update_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 .show ()
See https://plot.ly/python/reference/#histogram2dcontour for more information and chart attribute options!