{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### New to Plotly?\n",
"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/).\n",
"
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).\n",
"
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Version Check\n",
"Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'2.3.0'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly\n",
"plotly.__version__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Basic 2D Histogram Contour"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"import numpy as np\n",
"\n",
"x = np.random.uniform(-1, 1, size=500)\n",
"y = np.random.uniform(-1, 1, size=500)\n",
"\n",
"trace = [go.Histogram2dContour(\n",
" x = x,\n",
" y = y\n",
")]\n",
"\n",
"py.iplot(trace, filename = \"Basic Histogram2dContour\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2D Histogram Contour Colorscale"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"import numpy as np\n",
"\n",
"x = np.random.uniform(-1, 1, size=500)\n",
"y = np.random.uniform(-1, 1, size=500)\n",
"\n",
"trace = [go.Histogram2dContour(\n",
" x = x,\n",
" y = y,\n",
" colorscale = 'Blues'\n",
")]\n",
"\n",
"py.iplot(trace, filename = \"Histogram2dContour Colorscale\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2D Histogram Contour Styled"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"import numpy as np\n",
"\n",
"x = np.random.uniform(-1, 1, size=500)\n",
"y = np.random.uniform(-1, 1, size=500)\n",
"\n",
"trace = [go.Histogram2dContour(\n",
" x = x,\n",
" y = y,\n",
" colorscale = 'Jet',\n",
" contours = dict(\n",
" showlabels = True,\n",
" labelfont = dict(\n",
" family = 'Raleway',\n",
" color = 'white'\n",
" )\n",
" ),\n",
" hoverlabel = dict(\n",
" bgcolor = 'white',\n",
" bordercolor = 'black',\n",
" font = dict(\n",
" family = 'Raleway',\n",
" color = 'black'\n",
" )\n",
" )\n",
" \n",
")]\n",
"\n",
"py.iplot(trace, filename = \"Histogram2dContour Styled\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2D Histogram Contour Subplot"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"import numpy as np\n",
"\n",
"t = np.linspace(-1, 1.2, 2000)\n",
"x = (t**3) + (0.3 * np.random.randn(2000))\n",
"y = (t**6) + (0.3 * np.random.randn(2000))\n",
"\n",
"data = [\n",
" go.Histogram2dContour(\n",
" x = x,\n",
" y = y,\n",
" colorscale = 'Blues',\n",
" reversescale = True,\n",
" xaxis = 'x',\n",
" yaxis = 'y'\n",
" ),\n",
" go.Scatter(\n",
" x = x,\n",
" y = y,\n",
" xaxis = 'x',\n",
" yaxis = 'y',\n",
" mode = 'markers',\n",
" marker = dict(\n",
" color = 'rgba(0,0,0,0.3)',\n",
" size = 3\n",
" )\n",
" ),\n",
" go.Histogram(\n",
" y = y,\n",
" xaxis = 'x2',\n",
" marker = dict(\n",
" color = 'rgba(0,0,0,1)'\n",
" )\n",
" ),\n",
" go.Histogram(\n",
" x = x,\n",
" yaxis = 'y2',\n",
" marker = dict(\n",
" color = 'rgba(0,0,0,1)'\n",
" )\n",
" )\n",
"]\n",
"\n",
"layout = go.Layout(\n",
" autosize = False,\n",
" xaxis = dict(\n",
" zeroline = False,\n",
" domain = [0,0.85],\n",
" showgrid = False\n",
" ),\n",
" yaxis = dict(\n",
" zeroline = False,\n",
" domain = [0,0.85],\n",
" showgrid = False\n",
" ),\n",
" xaxis2 = dict(\n",
" zeroline = False,\n",
" domain = [0.85,1],\n",
" showgrid = False\n",
" ),\n",
" yaxis2 = dict(\n",
" zeroline = False,\n",
" domain = [0.85,1],\n",
" showgrid = False\n",
" ),\n",
" height = 600,\n",
" width = 600,\n",
" bargap = 0,\n",
" hovermode = 'closest',\n",
" showlegend = False\n",
")\n",
"\n",
"\n",
"\n",
"fig = go.Figure(data=data,layout=layout)\n",
"py.iplot(fig, filename='Histogram2dContour Subplot')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Reference\n",
"See https://plotly.com/python/reference/#histogram2dcontour for more information and chart attribute options!"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting git+https://github.com/plotly/publisher.git\n",
" Cloning https://github.com/plotly/publisher.git to c:\\users\\branden\\appdata\\local\\temp\\pip-99s09b37-build\n",
"Installing collected packages: publisher\n",
" Found existing installation: publisher 0.11\n",
" Uninstalling publisher-0.11:\n",
" Successfully uninstalled publisher-0.11\n",
" Running setup.py install for publisher: started\n",
" Running setup.py install for publisher: finished with status 'done'\n",
"Successfully installed publisher-0.11\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\Branden\\Anaconda3\\envs\\ipykernel_py2\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning:\n",
"\n",
"The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead.\n",
"\n",
"C:\\Users\\Branden\\Anaconda3\\envs\\ipykernel_py2\\lib\\site-packages\\publisher\\publisher.py:53: UserWarning:\n",
"\n",
"Did you \"Save\" this notebook before running this command? Remember to save, always save.\n",
"\n"
]
}
],
"source": [
"from IPython.display import display, HTML\n",
"\n",
"display(HTML(''))\n",
"display(HTML(''))\n",
"\n",
"! pip install git+https://github.com/plotly/publisher.git --upgrade\n",
"import publisher\n",
"publisher.publish(\n",
" 'histogram2dcontour.ipynb', 'python/2d-histogram-contour/', '2D Histogram Contour',\n",
" 'How to make 2D Histogram Contour plots in Python with Plotly.',\n",
" title = '2D Histogram Contour | Plotly',\n",
" has_thumbnail='true', thumbnail='thumbnail/hist2dcontour.png', \n",
" language='python', \n",
" # page_type='example_index', // note this is only if you want the tutorial to appear on the main page: plot.ly/python\n",
" display_as='statistical', \n",
" order=30, \n",
" ipynb='~notebook_demo/199',\n",
" uses_plotly_offline=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}