{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Plotly Express Gallery\n",
"\n",
"Plotly Express is a terse, consistent, high-level wrapper around [Plotly.py](https://plot.ly/python) for rapid data exploration and figure generation.\n",
"\n",
"This notebook demonstrates various `plotly_express` features. [Reference documentation](https://plotly.github.io/plotly_express/plotly_express/) and a [step by step walkthrough notebook](https://nbviewer.jupyter.org/github/plotly/plotly_express/blob/gh-pages/walkthrough.ipynb) are also available.\n",
"\n",
"You can also read our [Medium announcement article](https://medium.com/@plotlygraphs/introducing-plotly-express-808df010143d) for more information on this library.\n",
"\n",
"## A single import"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import plotly_express as px"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Built-in sample datasets"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" Each row represents a flower.\n",
"\n",
" https://en.wikipedia.org/wiki/Iris_flower_data_set\n",
"\n",
" Returns:\n",
" A `pandas.DataFrame` with 150 rows and the following columns: `['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species',\n",
" 'species_id']`.\n",
" \n"
]
}
],
"source": [
"print(px.data.iris.__doc__)\n",
"iris = px.data.iris()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"tips = px.data.tips()\n",
"gapminder = px.data.gapminder()\n",
"election = px.data.election()\n",
"wind = px.data.wind()\n",
"carshare = px.data.carshare()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Scatter and Line plots"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"linkText": "Export to plot.ly",
"plotlyServerURL": "https://plot.ly",
"showLink": false
},
"data": [
{
"hoverlabel": {
"namelength": 0
},
"hovertemplate": "sepal_width=%{x}
sepal_length=%{y}",
"legendgroup": "",
"marker": {
"color": "#636efa",
"symbol": "circle"
},
"mode": "markers",
"name": "",
"showlegend": false,
"type": "scatter",
"uid": "98005bfc-4121-4bcd-b437-5de38018763d",
"x": [
3.5,
3.0,
3.2,
3.1,
3.6,
3.9,
3.4,
3.4,
2.9,
3.1,
3.7,
3.4,
3.0,
3.0,
4.0,
4.4,
3.9,
3.5,
3.8,
3.8,
3.4,
3.7,
3.6,
3.3,
3.4,
3.0,
3.4,
3.5,
3.4,
3.2,
3.1,
3.4,
4.1,
4.2,
3.1,
3.2,
3.5,
3.1,
3.0,
3.4,
3.5,
2.3,
3.2,
3.5,
3.8,
3.0,
3.8,
3.2,
3.7,
3.3,
3.2,
3.2,
3.1,
2.3,
2.8,
2.8,
3.3,
2.4,
2.9,
2.7,
2.0,
3.0,
2.2,
2.9,
2.9,
3.1,
3.0,
2.7,
2.2,
2.5,
3.2,
2.8,
2.5,
2.8,
2.9,
3.0,
2.8,
3.0,
2.9,
2.6,
2.4,
2.4,
2.7,
2.7,
3.0,
3.4,
3.1,
2.3,
3.0,
2.5,
2.6,
3.0,
2.6,
2.3,
2.7,
3.0,
2.9,
2.9,
2.5,
2.8,
3.3,
2.7,
3.0,
2.9,
3.0,
3.0,
2.5,
2.9,
2.5,
3.6,
3.2,
2.7,
3.0,
2.5,
2.8,
3.2,
3.0,
3.8,
2.6,
2.2,
3.2,
2.8,
2.8,
2.7,
3.3,
3.2,
2.8,
3.0,
2.8,
3.0,
2.8,
3.8,
2.8,
2.8,
2.6,
3.0,
3.4,
3.1,
3.0,
3.1,
3.1,
3.1,
2.7,
3.2,
3.3,
3.0,
2.5,
3.0,
3.4,
3.0
],
"xaxis": "x",
"y": [
5.1,
4.9,
4.7,
4.6,
5.0,
5.4,
4.6,
5.0,
4.4,
4.9,
5.4,
4.8,
4.8,
4.3,
5.8,
5.7,
5.4,
5.1,
5.7,
5.1,
5.4,
5.1,
4.6,
5.1,
4.8,
5.0,
5.0,
5.2,
5.2,
4.7,
4.8,
5.4,
5.2,
5.5,
4.9,
5.0,
5.5,
4.9,
4.4,
5.1,
5.0,
4.5,
4.4,
5.0,
5.1,
4.8,
5.1,
4.6,
5.3,
5.0,
7.0,
6.4,
6.9,
5.5,
6.5,
5.7,
6.3,
4.9,
6.6,
5.2,
5.0,
5.9,
6.0,
6.1,
5.6,
6.7,
5.6,
5.8,
6.2,
5.6,
5.9,
6.1,
6.3,
6.1,
6.4,
6.6,
6.8,
6.7,
6.0,
5.7,
5.5,
5.5,
5.8,
6.0,
5.4,
6.0,
6.7,
6.3,
5.6,
5.5,
5.5,
6.1,
5.8,
5.0,
5.6,
5.7,
5.7,
6.2,
5.1,
5.7,
6.3,
5.8,
7.1,
6.3,
6.5,
7.6,
4.9,
7.3,
6.7,
7.2,
6.5,
6.4,
6.8,
5.7,
5.8,
6.4,
6.5,
7.7,
7.7,
6.0,
6.9,
5.6,
7.7,
6.3,
6.7,
7.2,
6.2,
6.1,
6.4,
7.2,
7.4,
7.9,
6.4,
6.3,
6.1,
7.7,
6.3,
6.4,
6.0,
6.9,
6.7,
6.9,
5.8,
6.8,
6.7,
6.7,
6.3,
6.5,
6.2,
5.9
],
"yaxis": "y"
}
],
"layout": {
"grid": {
"xaxes": [
"x"
],
"xgap": 0.1,
"xside": "bottom",
"yaxes": [
"y"
],
"ygap": 0.1,
"yside": "left"
},
"height": 600,
"legend": {
"tracegroupgap": 0
},
"margin": {
"t": 60
},
"template": {
"data": {
"bar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0508b8"
],
[
0.0893854748603352,
"#1910d8"
],
[
0.1787709497206704,
"#3c19f0"
],
[
0.2681564245810056,
"#6b1cfb"
],
[
0.3575418994413408,
"#981cfd"
],
[
0.44692737430167595,
"#bf1cfd"
],
[
0.5363128491620112,
"#dd2bfd"
],
[
0.6256983240223464,
"#f246fe"
],
[
0.7150837988826816,
"#fc67fd"
],
[
0.8044692737430168,
"#fe88fc"
],
[
0.8938547486033519,
"#fea5fd"
],
[
0.9832402234636871,
"#febefe"
],
[
1.0,
"#fec3fe"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0508b8"
],
[
0.0893854748603352,
"#1910d8"
],
[
0.1787709497206704,
"#3c19f0"
],
[
0.2681564245810056,
"#6b1cfb"
],
[
0.3575418994413408,
"#981cfd"
],
[
0.44692737430167595,
"#bf1cfd"
],
[
0.5363128491620112,
"#dd2bfd"
],
[
0.6256983240223464,
"#f246fe"
],
[
0.7150837988826816,
"#fc67fd"
],
[
0.8044692737430168,
"#fe88fc"
],
[
0.8938547486033519,
"#fea5fd"
],
[
0.9832402234636871,
"#febefe"
],
[
1.0,
"#fec3fe"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0508b8"
],
[
0.0893854748603352,
"#1910d8"
],
[
0.1787709497206704,
"#3c19f0"
],
[
0.2681564245810056,
"#6b1cfb"
],
[
0.3575418994413408,
"#981cfd"
],
[
0.44692737430167595,
"#bf1cfd"
],
[
0.5363128491620112,
"#dd2bfd"
],
[
0.6256983240223464,
"#f246fe"
],
[
0.7150837988826816,
"#fc67fd"
],
[
0.8044692737430168,
"#fe88fc"
],
[
0.8938547486033519,
"#fea5fd"
],
[
0.9832402234636871,
"#febefe"
],
[
1.0,
"#fec3fe"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0.0,
"#0508b8"
],
[
0.0893854748603352,
"#1910d8"
],
[
0.1787709497206704,
"#3c19f0"
],
[
0.2681564245810056,
"#6b1cfb"
],
[
0.3575418994413408,
"#981cfd"
],
[
0.44692737430167595,
"#bf1cfd"
],
[
0.5363128491620112,
"#dd2bfd"
],
[
0.6256983240223464,
"#f246fe"
],
[
0.7150837988826816,
"#fc67fd"
],
[
0.8044692737430168,
"#fe88fc"
],
[
0.8938547486033519,
"#fea5fd"
],
[
0.9832402234636871,
"#febefe"
],
[
1.0,
"#fec3fe"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#506784",
"arrowhead": 0,
"arrowwidth": 1
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0.0,
"#0508b8"
],
[
0.0893854748603352,
"#1910d8"
],
[
0.1787709497206704,
"#3c19f0"
],
[
0.2681564245810056,
"#6b1cfb"
],
[
0.3575418994413408,
"#981cfd"
],
[
0.44692737430167595,
"#bf1cfd"
],
[
0.5363128491620112,
"#dd2bfd"
],
[
0.6256983240223464,
"#f246fe"
],
[
0.7150837988826816,
"#fc67fd"
],
[
0.8044692737430168,
"#fe88fc"
],
[
0.8938547486033519,
"#fea5fd"
],
[
0.9832402234636871,
"#febefe"
],
[
1.0,
"#fec3fe"
]
],
"sequentialminus": [
[
0.0,
"#0508b8"
],
[
0.0893854748603352,
"#1910d8"
],
[
0.1787709497206704,
"#3c19f0"
],
[
0.2681564245810056,
"#6b1cfb"
],
[
0.3575418994413408,
"#981cfd"
],
[
0.44692737430167595,
"#bf1cfd"
],
[
0.5363128491620112,
"#dd2bfd"
],
[
0.6256983240223464,
"#f246fe"
],
[
0.7150837988826816,
"#fc67fd"
],
[
0.8044692737430168,
"#fe88fc"
],
[
0.8938547486033519,
"#fea5fd"
],
[
0.9832402234636871,
"#febefe"
],
[
1.0,
"#fec3fe"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#19d3f3",
"#e763fa",
"#FECB52",
"#FFA15A",
"#FF6692",
"#B6E880"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"fillcolor": "#506784",
"line": {
"width": 0
},
"opacity": 0.4
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"xaxis": {
"title": {
"text": "sepal_width"
}
},
"yaxis": {
"title": {
"text": "sepal_length"
}
}
}
},
"text/html": [
"