{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plots with Plotly Express\n",
"====================\n",
"\n",
"The plotly library has two plotting interfaces, or APIs you can work with. The simplest"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Creating a Line Plot with Plotly Express\n",
"----------------------------------------------"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import plotly.express as px"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" r | \n",
" 1s | \n",
" 2s | \n",
" 3s | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0.000000 | \n",
" 0.564190 | \n",
" 0.199471 | \n",
" 0.108578 | \n",
"
\n",
" \n",
" 1 | \n",
" 0.517241 | \n",
" 0.336349 | \n",
" 0.114183 | \n",
" 0.061683 | \n",
"
\n",
" \n",
" 2 | \n",
" 1.034483 | \n",
" 0.200519 | \n",
" 0.057408 | \n",
" 0.029966 | \n",
"
\n",
" \n",
" 3 | \n",
" 1.551724 | \n",
" 0.119542 | \n",
" 0.020580 | \n",
" 0.009313 | \n",
"
\n",
" \n",
" 4 | \n",
" 2.068966 | \n",
" 0.071266 | \n",
" -0.002445 | \n",
" -0.003390 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" r 1s 2s 3s\n",
"0 0.000000 0.564190 0.199471 0.108578\n",
"1 0.517241 0.336349 0.114183 0.061683\n",
"2 1.034483 0.200519 0.057408 0.029966\n",
"3 1.551724 0.119542 0.020580 0.009313\n",
"4 2.068966 0.071266 -0.002445 -0.003390"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s_orbitals = pd.read_csv(\"s_orbitals_1D.csv\")\n",
"\n",
"s_orbitals.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "r=%{x}
1s=%{y}",
"legendgroup": "",
"line": {
"color": "#636efa",
"dash": "solid"
},
"mode": "lines",
"name": "",
"orientation": "v",
"showlegend": false,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.5641895835477563,
0.3363488807217191,
0.20051871367663632,
0.11954181161018657,
0.0712663893609965,
0.04248637513638252,
0.02532879928974393,
0.015100089649934704,
0.009002112766095133,
0.005366725372643292,
0.00319944239466206,
0.001907388756827536,
0.0011371143533454272,
0.0006779053551384148,
0.0004041420013504466,
0.00024093445496118797,
0.00014363617588241675,
8.563055468944057e-05,
5.104975714769703e-05,
3.043396967695007e-05,
1.8143602674107897e-05,
1.0816542222068907e-05,
6.4484208425023845e-06,
3.844309069230966e-06,
2.2918343235855563e-06,
1.3663065253532307e-06,
8.145412179281059e-07,
4.855992293034488e-07,
2.894962296689037e-07,
1.7258690281021735e-07
],
"yaxis": "y"
}
],
"layout": {
"legend": {
"tracegroupgap": 0
},
"margin": {
"t": 60
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"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": {
"line": {
"color": "#2a3f5f"
}
},
"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": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"xaxis": {
"anchor": "y",
"domain": [
0,
1
],
"title": {
"text": "r"
}
},
"yaxis": {
"anchor": "x",
"domain": [
0,
1
],
"title": {
"text": "1s"
}
}
}
},
"text/html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = px.line(s_orbitals, x=\"r\", y=\"1s\")\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Adding more lines"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "variable=1s
r=%{x}
value=%{y}",
"legendgroup": "1s",
"line": {
"color": "#636efa",
"dash": "solid"
},
"mode": "lines",
"name": "1s",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.5641895835477563,
0.3363488807217191,
0.20051871367663632,
0.11954181161018657,
0.0712663893609965,
0.04248637513638252,
0.02532879928974393,
0.015100089649934704,
0.009002112766095133,
0.005366725372643292,
0.00319944239466206,
0.001907388756827536,
0.0011371143533454272,
0.0006779053551384148,
0.0004041420013504466,
0.00024093445496118797,
0.00014363617588241675,
8.563055468944057e-05,
5.104975714769703e-05,
3.043396967695007e-05,
1.8143602674107897e-05,
1.0816542222068907e-05,
6.4484208425023845e-06,
3.844309069230966e-06,
2.2918343235855563e-06,
1.3663065253532307e-06,
8.145412179281059e-07,
4.855992293034488e-07,
2.894962296689037e-07,
1.7258690281021735e-07
],
"yaxis": "y"
},
{
"hovertemplate": "variable=2s
r=%{x}
value=%{y}",
"legendgroup": "2s",
"line": {
"color": "#EF553B",
"dash": "solid"
},
"mode": "lines",
"name": "2s",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.19947114020071635,
0.11418340605999756,
0.05740834554551136,
0.020579878840982453,
-0.0024446231413026475,
-0.01604402410682839,
-0.023318296724106957,
-0.02644400103987382,
-0.026934161427984223,
-0.025827653774468287,
-0.023826734180701623,
-0.02139650953591212,
-0.018836553620043925,
-0.016332198296584454,
-0.013991044135991657,
-0.01186876337231226,
-0.009987179368172054,
-0.008346802732693224,
-0.006935411686185676,
-0.005733828563090528,
-0.004719724775983336,
-0.003870052824954975,
-0.0031625335052826763,
-0.0025765026269379057,
-0.002093331927681056,
-0.0016965742776650211,
-0.0013719369762257578,
-0.0011071539503473315,
-0.0008918043189450667,
-0.0007171084046137923
],
"yaxis": "y"
},
{
"hovertemplate": "variable=3s
r=%{x}
value=%{y}",
"legendgroup": "3s",
"line": {
"color": "#00cc96",
"dash": "solid"
},
"mode": "lines",
"name": "3s",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.10857833597842664,
0.06168253588459791,
0.02996558295809507,
0.009313168900508897,
-0.0033900971789849613,
-0.010486002320077369,
-0.013719813897071064,
-0.014379063165844455,
-0.01340197363062784,
-0.011461883190709971,
-0.009032725332978291,
-0.006439603695379165,
-0.003897667423914713,
-0.0015418323926003879,
0.0005506364330305373,
0.002343089318023595,
0.003826747956025547,
0.005011267254920848,
0.005917829749914995,
0.006574168821484719,
0.007011050704153348,
0.0072598508805376445,
0.007350943591930802,
0.007312688458966705,
0.007170849277996254,
0.0069483198892820565,
0.006665062958154539,
0.006338191449591971,
0.005982141007296371,
0.00560889556021509
],
"yaxis": "y"
}
],
"layout": {
"legend": {
"title": {
"text": "variable"
},
"tracegroupgap": 0
},
"margin": {
"t": 60
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"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": {
"line": {
"color": "#2a3f5f"
}
},
"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": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"xaxis": {
"anchor": "y",
"domain": [
0,
1
],
"title": {
"text": "r"
}
},
"yaxis": {
"anchor": "x",
"domain": [
0,
1
],
"title": {
"text": "value"
}
}
}
},
"text/html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = px.line(s_orbitals, x=\"r\", y=[\"1s\", \"2s\", \"3s\"])\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Changing labels - plotly also supports using symbols."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "orbital=1s
r=%{x}
$\\psi$=%{y}",
"legendgroup": "1s",
"line": {
"color": "#636efa",
"dash": "solid"
},
"mode": "lines",
"name": "1s",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.5641895835477563,
0.3363488807217191,
0.20051871367663632,
0.11954181161018657,
0.0712663893609965,
0.04248637513638252,
0.02532879928974393,
0.015100089649934704,
0.009002112766095133,
0.005366725372643292,
0.00319944239466206,
0.001907388756827536,
0.0011371143533454272,
0.0006779053551384148,
0.0004041420013504466,
0.00024093445496118797,
0.00014363617588241675,
8.563055468944057e-05,
5.104975714769703e-05,
3.043396967695007e-05,
1.8143602674107897e-05,
1.0816542222068907e-05,
6.4484208425023845e-06,
3.844309069230966e-06,
2.2918343235855563e-06,
1.3663065253532307e-06,
8.145412179281059e-07,
4.855992293034488e-07,
2.894962296689037e-07,
1.7258690281021735e-07
],
"yaxis": "y"
},
{
"hovertemplate": "orbital=2s
r=%{x}
$\\psi$=%{y}",
"legendgroup": "2s",
"line": {
"color": "#EF553B",
"dash": "solid"
},
"mode": "lines",
"name": "2s",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.19947114020071635,
0.11418340605999756,
0.05740834554551136,
0.020579878840982453,
-0.0024446231413026475,
-0.01604402410682839,
-0.023318296724106957,
-0.02644400103987382,
-0.026934161427984223,
-0.025827653774468287,
-0.023826734180701623,
-0.02139650953591212,
-0.018836553620043925,
-0.016332198296584454,
-0.013991044135991657,
-0.01186876337231226,
-0.009987179368172054,
-0.008346802732693224,
-0.006935411686185676,
-0.005733828563090528,
-0.004719724775983336,
-0.003870052824954975,
-0.0031625335052826763,
-0.0025765026269379057,
-0.002093331927681056,
-0.0016965742776650211,
-0.0013719369762257578,
-0.0011071539503473315,
-0.0008918043189450667,
-0.0007171084046137923
],
"yaxis": "y"
},
{
"hovertemplate": "orbital=3s
r=%{x}
$\\psi$=%{y}",
"legendgroup": "3s",
"line": {
"color": "#00cc96",
"dash": "solid"
},
"mode": "lines",
"name": "3s",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.10857833597842664,
0.06168253588459791,
0.02996558295809507,
0.009313168900508897,
-0.0033900971789849613,
-0.010486002320077369,
-0.013719813897071064,
-0.014379063165844455,
-0.01340197363062784,
-0.011461883190709971,
-0.009032725332978291,
-0.006439603695379165,
-0.003897667423914713,
-0.0015418323926003879,
0.0005506364330305373,
0.002343089318023595,
0.003826747956025547,
0.005011267254920848,
0.005917829749914995,
0.006574168821484719,
0.007011050704153348,
0.0072598508805376445,
0.007350943591930802,
0.007312688458966705,
0.007170849277996254,
0.0069483198892820565,
0.006665062958154539,
0.006338191449591971,
0.005982141007296371,
0.00560889556021509
],
"yaxis": "y"
}
],
"layout": {
"legend": {
"title": {
"text": "orbital"
},
"tracegroupgap": 0
},
"margin": {
"t": 60
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"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": {
"line": {
"color": "#2a3f5f"
}
},
"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": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"xaxis": {
"anchor": "y",
"domain": [
0,
1
],
"title": {
"text": "r"
}
},
"yaxis": {
"anchor": "x",
"domain": [
0,
1
],
"title": {
"text": "$\\psi$"
}
}
}
},
"text/html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = px.line(s_orbitals, x=\"r\", y=[\"1s\", \"2s\", \"3s\"], labels={\"r\":\"r\", \"value\":r\"$\\psi$\", \"variable\": \"orbital\"})\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Modifying the Layout of a Plotly Figure\n",
"---------------------------------------------\n",
"\n",
"When we create a figure with plotly express, we get a figure variable back. Above, we have been working with `fig.show()` to show the figure, but you can also use this variable to update or change things about the figure.\n",
"\n",
"The information about the layout of a plotly figure is stored in `fig.layout`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can change or update the layout of a figure using the `fig.update_layout` function. The `update_layout` function takes key word arguments. You can see a list [here](https://plotly.com/python/reference/layout/).\n",
"\n",
"The example below makes several changes to this figure. You can try each of these individually to see how they change the figure."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "orbital=1s
r=%{x}
$\\psi$=%{y}",
"legendgroup": "1s",
"line": {
"color": "#636efa",
"dash": "solid"
},
"mode": "lines",
"name": "1s",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.5641895835477563,
0.3363488807217191,
0.20051871367663632,
0.11954181161018657,
0.0712663893609965,
0.04248637513638252,
0.02532879928974393,
0.015100089649934704,
0.009002112766095133,
0.005366725372643292,
0.00319944239466206,
0.001907388756827536,
0.0011371143533454272,
0.0006779053551384148,
0.0004041420013504466,
0.00024093445496118797,
0.00014363617588241675,
8.563055468944057e-05,
5.104975714769703e-05,
3.043396967695007e-05,
1.8143602674107897e-05,
1.0816542222068907e-05,
6.4484208425023845e-06,
3.844309069230966e-06,
2.2918343235855563e-06,
1.3663065253532307e-06,
8.145412179281059e-07,
4.855992293034488e-07,
2.894962296689037e-07,
1.7258690281021735e-07
],
"yaxis": "y"
},
{
"hovertemplate": "orbital=2s
r=%{x}
$\\psi$=%{y}",
"legendgroup": "2s",
"line": {
"color": "#EF553B",
"dash": "solid"
},
"mode": "lines",
"name": "2s",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.19947114020071635,
0.11418340605999756,
0.05740834554551136,
0.020579878840982453,
-0.0024446231413026475,
-0.01604402410682839,
-0.023318296724106957,
-0.02644400103987382,
-0.026934161427984223,
-0.025827653774468287,
-0.023826734180701623,
-0.02139650953591212,
-0.018836553620043925,
-0.016332198296584454,
-0.013991044135991657,
-0.01186876337231226,
-0.009987179368172054,
-0.008346802732693224,
-0.006935411686185676,
-0.005733828563090528,
-0.004719724775983336,
-0.003870052824954975,
-0.0031625335052826763,
-0.0025765026269379057,
-0.002093331927681056,
-0.0016965742776650211,
-0.0013719369762257578,
-0.0011071539503473315,
-0.0008918043189450667,
-0.0007171084046137923
],
"yaxis": "y"
},
{
"hovertemplate": "orbital=3s
r=%{x}
$\\psi$=%{y}",
"legendgroup": "3s",
"line": {
"color": "#00cc96",
"dash": "solid"
},
"mode": "lines",
"name": "3s",
"orientation": "v",
"showlegend": true,
"type": "scatter",
"x": [
0,
0.5172413793103449,
1.0344827586206895,
1.5517241379310347,
2.0689655172413794,
2.586206896551724,
3.1034482758620694,
3.6206896551724146,
4.137931034482759,
4.655172413793104,
5.172413793103448,
5.689655172413794,
6.206896551724139,
6.724137931034483,
7.241379310344829,
7.758620689655171,
8.275862068965516,
8.793103448275865,
9.310344827586208,
9.827586206896552,
10.344827586206897,
10.86206896551724,
11.379310344827587,
11.896551724137932,
12.413793103448276,
12.93103448275862,
13.448275862068966,
13.965517241379311,
14.482758620689657,
15
],
"xaxis": "x",
"y": [
0.10857833597842664,
0.06168253588459791,
0.02996558295809507,
0.009313168900508897,
-0.0033900971789849613,
-0.010486002320077369,
-0.013719813897071064,
-0.014379063165844455,
-0.01340197363062784,
-0.011461883190709971,
-0.009032725332978291,
-0.006439603695379165,
-0.003897667423914713,
-0.0015418323926003879,
0.0005506364330305373,
0.002343089318023595,
0.003826747956025547,
0.005011267254920848,
0.005917829749914995,
0.006574168821484719,
0.007011050704153348,
0.0072598508805376445,
0.007350943591930802,
0.007312688458966705,
0.007170849277996254,
0.0069483198892820565,
0.006665062958154539,
0.006338191449591971,
0.005982141007296371,
0.00560889556021509
],
"yaxis": "y"
}
],
"layout": {
"font": {
"color": "dark gray",
"family": "Times New Roman",
"size": 20
},
"legend": {
"title": {
"text": "orbital"
},
"tracegroupgap": 0
},
"margin": {
"t": 60
},
"plot_bgcolor": "white",
"showlegend": true,
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"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": {
"line": {
"color": "#2a3f5f"
}
},
"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": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"xaxis": {
"anchor": "y",
"domain": [
0,
1
],
"gridcolor": "#d3d3d3",
"linecolor": "lightslategray",
"title": {
"text": "r"
}
},
"yaxis": {
"anchor": "x",
"domain": [
0,
1
],
"gridcolor": "#d3d3d3",
"linecolor": "lightslategray",
"title": {
"text": "$\\psi$"
},
"zerolinecolor": "#d3d3d3"
}
}
},
"text/html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig.update_layout(\n",
" font_family=\"Times New Roman\",\n",
" font_size=20,\n",
" font_color=\"dark gray\",\n",
" showlegend=True,\n",
" yaxis=dict(gridcolor=\"#d3d3d3\", linecolor=\"lightslategray\", zerolinecolor=\"#d3d3d3\"),\n",
" xaxis=dict(gridcolor=\"#d3d3d3\", linecolor=\"lightslategray\"),\n",
" plot_bgcolor=\"white\",\n",
")\n",
"\n",
"fig.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exporting Plots as Images\n",
"\n",
"To export a figure from plotly, we have to have another package installed\n",
"\n",
" pip install -U kaleido\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"fig.write_image(\"s_orbitals.png\")\n",
"fig.write_image(\"s_orbitals.svg\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plotly also allows you to save an interactive html version of your file. If we want our mathematical symbols to also show up, we will need to add the argument `include_mathjax=\"cdn\"`."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"fig.write_html(\"s_orbitals.html\", include_mathjax=\"cdn\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Creating a Map Plot with Plotly Express\n",
"----------------------------------------------\n",
"\n",
"Plotly Express has some fun maps you can make which are probably not the kind of maps you usually make as a physical scientist. For example, we can create a map which shows locations of institutions of the students registered for this webinar. We will read in a file called `visualization_institutions.csv` which has institution names, the latitude, the longitude, and the count of the number of students."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" institution | \n",
" lat | \n",
" lon | \n",
" count | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Washington university in St. Louis | \n",
" 38.648789 | \n",
" -90.310796 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" Rutgers University, New Brunswick | \n",
" 40.500819 | \n",
" -74.447399 | \n",
" 1 | \n",
"
\n",
" \n",
" 2 | \n",
" Federal Institute of São Paulo | \n",
" -22.727627 | \n",
" -47.652870 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" University of North Texas | \n",
" 33.207488 | \n",
" -97.152586 | \n",
" 1 | \n",
"
\n",
" \n",
" 4 | \n",
" TCIS | \n",
" 33.451189 | \n",
" -84.481229 | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" institution lat lon count\n",
"0 Washington university in St. Louis 38.648789 -90.310796 1\n",
"1 Rutgers University, New Brunswick 40.500819 -74.447399 1\n",
"2 Federal Institute of São Paulo -22.727627 -47.652870 1\n",
"3 University of North Texas 33.207488 -97.152586 1\n",
"4 TCIS 33.451189 -84.481229 1"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"student_locations = pd.read_csv(\"visualization_institutions.csv\")\n",
"student_locations.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This plot is very easy to create once we have our data in the right format. In fact, you may be more interested in how we obtained the latitude/longitude data and unique institutions. We used the `google maps` API and some `pandas` magic to do this, but we would be happy to provide you with a script upon request (you will have to make your own Google Maps API key).\n",
"\n",
"Plotly Express has a `scatter_geo` function which allows us to pass latitude and longitude as coordinates. For this plot, we are setting the marker size to be the count of the number of students, and for the institution name to show up when we hover over a point."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"geo": "geo",
"hovertemplate": "%{hovertext}
count=%{marker.size}
lat=%{lat}
lon=%{lon}",
"hovertext": [
"Washington university in St. Louis",
"Rutgers University, New Brunswick",
"Federal Institute of São Paulo",
"University of North Texas",
"TCIS",
"University of Pavia",
"Cinvestav Merida",
"Stony Brook university",
"Monash University Malaysia",
"Leeds",
"University of Kentucky",
"Colorado State University",
"Shahjalal University of Science and Technology",
"Syngenta",
"California State University, Long Beach",
"Purdue University",
"RWTH Aachen",
"NISER",
"University of Florida",
"R1",
"Hacettepe University",
"Aix-Marseille Université",
"Cinvestav",
"Brown University",
"University of southern Indiana",
"Abdullah Gül University",
"University of Phayao",
"University of North Carolina - Chapel Hill",
"Georgia Institute of Technology",
"UC Berkeley",
"UC San Diego",
"University of Southern California",
"University of Pittsburgh",
"University of Zurich",
"Lafayette College",
"Tokyo Institute of Technology",
"UNAM",
"University of Innsbruck",
"Cal Poly SLO",
"Institute of Physics La Plata - National University of La Plata",
"Harvard University",
"Northwestern University",
"Ladoke Akintola University of Technology",
"Ege University",
"Trinity College Dublin",
"University of Douala",
"University of Maryland Baltimore County",
"University of Tuebingen",
"University of Calgary",
"College of Pharmacy, Gachon University",
"İzmir Biomedicine and Genome Center",
"University of Texas at Dallas",
"Temple University",
"Universidade Federal do Rio de Janeiro",
"UTFPR",
"University of Utah",
"University of Rochester",
"University of Notre Dame",
"Technical University of Denmark",
"Tribhuvan University",
"Sabanci üniversitesi",
"Ramkhamhaeng University",
"University of São Paulo",
"University of peshawar",
"Caltech",
"Aix-Marseille University",
"Auburn University",
"Clemson University",
"CICESE",
"University of Girona/IQCC",
"WILLIAM PATERSON UNIVERSITY",
"Western Carolina University",
"Universidade Federal de Pernambuco",
"Fluminense Federal University",
"Univer",
"CSIR-CLRI",
"Cornell University"
],
"lat": [
38.6487895,
40.5008186,
-22.7276271,
33.207488,
33.45118850000001,
45.186733,
21.0218168,
40.914322,
3.0649648,
53.8007554,
38.0306511,
40.57341479999999,
24.9172232,
30.2434631,
33.7838235,
40.4237054,
50.7800778,
20.1702462,
29.6436325,
40.6564262,
39.8729919,
43.5174943,
25.7621707,
41.8267718,
37.9582437,
38.737118,
19.0284228,
35.9049122,
33.7756178,
37.8718992,
32.8800604,
34.0223519,
40.4443533,
47.3743221,
40.6983134,
35.6051229,
41.894154,
47.26335419999999,
35.3050053,
-34.91288180000001,
42.3770029,
42.0564594,
8.1705725,
38.4574615,
53.3437935,
4.0558562,
39.2556759,
48.5294782,
51.0775908,
37.4507452,
38.3939086,
32.9857619,
39.9805942,
-22.8625345,
-25.4391353,
40.7649368,
43.1305531,
41.7055716,
55.7855742,
27.6806722,
40.8924593,
13.7499094,
-23.5613991,
34.00859,
34.1376576,
43.2922073,
32.5933574,
34.6738437,
31.8675086,
41.9857028,
40.9473619,
35.3090108,
-8.0517328,
42.2780436,
28.6417796,
13.0083386,
42.4534492
],
"legendgroup": "",
"lon": [
-90.3107962,
-74.44739910000001,
-47.6528703,
-97.1525862,
-84.4812286,
9.1558938,
-89.6261303,
-73.1165224,
101.6009742,
-1.5490774,
-84.5039697,
-105.0865487,
91.8319132,
-91.0968864,
-118.1140904,
-86.92119459999999,
6.065686899999999,
85.68359079999999,
-82.3549302,
-111.9035176,
32.7368592,
5.448135,
-100.1163787,
-71.4025482,
-87.67469380000001,
35.473534,
99.8962444,
-79.0469134,
-84.39628499999999,
-122.2585399,
-117.2340135,
-118.285117,
-79.960835,
8.550981199999999,
-75.209746,
139.6835302,
-87.6377244,
11.3838006,
-120.6624942,
-57.9511217,
-71.11666009999999,
-87.67526699999999,
4.2651442,
27.2282167,
-6.254571599999999,
9.7342639,
-76.7109674,
9.043774,
-114.140695,
127.1288474,
27.0306084,
-96.7500993,
-75.1557376,
-43.2234737,
-49.26963199999999,
-111.8421021,
-77.6260033,
-86.2353388,
12.521381,
85.28346289999999,
29.3775718,
100.6195542,
-46.7307891,
71.4878186,
-118.125269,
5.359122699999999,
-85.4951663,
-82.8368654,
-116.6652197,
2.8272011,
-74.1967319,
-83.1863612,
-34.9507155,
-83.7382241,
-106.075081,
80.24362409999999,
-76.4735027
],
"marker": {
"color": "#636efa",
"size": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
5,
3,
1,
1,
1,
1,
1,
1,
7,
1,
1,
1,
3,
1,
1,
1,
1,
3,
3,
1,
2,
1,
1,
2,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
2,
1,
1,
1,
1,
4,
1,
2,
1,
2,
1,
1,
1,
1,
2,
1,
1,
1,
1,
1,
1,
1,
2,
1,
2,
1,
1,
1,
1
],
"sizemode": "area",
"sizeref": 0.0175,
"symbol": "circle"
},
"mode": "markers",
"name": "",
"showlegend": false,
"type": "scattergeo"
}
],
"layout": {
"geo": {
"center": {},
"domain": {
"x": [
0,
1
],
"y": [
0,
1
]
}
},
"legend": {
"itemsizing": "constant",
"tracegroupgap": 0
},
"margin": {
"t": 60
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"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,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"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": {
"line": {
"color": "#2a3f5f"
}
},
"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": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
}
}
},
"text/html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = px.scatter_geo(student_locations, lat=\"lat\", lon=\"lon\", size=\"count\", hover_name=\"institution\")\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}