#!/usr/bin/env python
# coding: utf-8
# #### New to Plotly?
# Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/).
#
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online).
#
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!
# #### Version Check
# Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version.
# In[1]:
import plotly
plotly.__version__
# #### Basic 2D Histogram Contour
# In[2]:
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")
# #### 2D Histogram Contour Colorscale
# In[3]:
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")
# #### 2D Histogram Contour Styled
# In[4]:
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")
# #### 2D Histogram Contour Subplot
# In[5]:
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')
# #### Reference
# See https://plotly.com/python/reference/#histogram2dcontour for more information and chart attribute options!
# In[6]:
from IPython.display import display, HTML
display(HTML(''))
display(HTML(''))
get_ipython().system(' 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)
# In[ ]: