{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Making 2D-Histograms" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A 2-D histogram is an extension of the traditional histogram, designed to visualize the relationship between two continuous variables. Instead of grouping values into bins along a single axis, a 2-D histogram divides both the x-axis and y-axis into bins, creating a grid where each cell represents the frequency of data points that fall within the corresponding ranges of both variables. The frequency or count for each bin is indicated by color or shading in the grid, often using a heat map or color gradient. This allows you to see how the two variables are distributed together, and where data points are concentrated or sparse.\n", "\n", "2-D histograms are particularly useful when you're analyzing the joint distribution of two continuous variables and want to explore any patterns or correlations between them. For example, in fields like meteorology or economics, 2-D histograms can be used to visualize how temperature and humidity co-vary, or how income and expenditure relate to one another. Unlike scatter plots, which display individual data points, 2-D histograms are beneficial when working with large datasets where overlapping points can obscure patterns. The binning process groups the data, making it easier to observe density, trends, or anomalies in the relationship between the variables. However, the choice of bin size is still important, as too many or too few bins can either obscure meaningful patterns or add unnecessary complexity." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting ready\n", "\n", "\n", "In addition to `plotly`, `numpy` and `pandas`, make sure the `scipy` Python library avaiable in your Python environment\n", "You can install it using the command:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```\n", "pip install scipy \n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this recipe we will create two data sets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Import the Python modules `numpy`, `pandas`; and the [`multivariate_normal`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.multivariate_normal.html) object from `scipy.stats`. This object will allow us to generate random samples from a bi-variate normal distribution. This will help us to create data sets to be used in this recipe." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "from scipy.stats import multivariate_normal" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Create the data set that we are going to use in this recipe" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "rv = multivariate_normal([1.0, 3.0], [[1.0, 0.3], [0.3, 0.5]])\n", "n = 200\n", "sample = rv.rvs(n)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
XY
02.3171203.128239
10.9955534.070351
21.5935384.044972
30.4705562.772609
40.4158543.184090
\n", "
" ], "text/plain": [ " X Y\n", "0 2.317120 3.128239\n", "1 0.995553 4.070351\n", "2 1.593538 4.044972\n", "3 0.470556 2.772609\n", "4 0.415854 3.184090" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data1 = pd.DataFrame(sample, columns=['X', 'Y'])\n", "data1.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to do it" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Import the `plotly.express` module as `px`" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import plotly.express as px" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Make a simple 2-D histogram plot to illustrate the distributions of the data set from `data1` using the function `density_heatmap`" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "coloraxis": "coloraxis", "hovertemplate": "X=%{x}
Y=%{y}
count=%{z}", "name": "", "type": "histogram2d", "x": [ 2.31712013454836, 0.9955529116690811, 1.5935376172499718, 0.470556383491882, 0.4158541115098898, -0.22167942099963578, 2.580265645305723, 3.9310544147650504, 2.8931706098195393, 0.7275794361740546, 2.0152089110594336, 2.7321084386647634, 1.324552882814132, 0.35025134091154864, 2.650036844272331, 0.17138726836009488, 1.8467812954548124, -0.25978469328708864, 0.20112104181319734, 1.8823185163963756, 1.0778911534705955, 1.491036853022197, 1.2736938497826842, 0.5540013289664579, 2.9060172357014915, -0.2838477734846878, 1.8189725170859496, 2.35418220242837, 1.2663379745732963, 1.5375968602562398, 1.8402136331248191, 0.8786000822702367, 1.5888778426382055, 0.19248465112718183, 0.5384097774666239, 1.0573066963645428, -0.9280367663576994, 2.0876392670005957, 1.339594614146936, 0.37031409099418877, 1.534614406589347, 1.7137536023177005, 0.5791939635283425, 0.750240518284518, 0.5161609767969657, 2.9968955064731797, 0.00820701237511623, 0.9597167346765632, 1.2639629095967337, 2.023902862326633, 1.74179617867757, 0.5019587874992837, 2.25305796323564, 2.7328107074969332, 2.367176612405366, 1.9305001326073732, 0.36451730845511454, 0.5105867334812165, 0.3302935715034603, 0.6452846847414433, 1.084982000292835, -0.3958921857473203, 1.6637282735289345, -1.3237533839282252, -0.01574845416352688, 1.1175169016700064, 1.5552121293363905, 1.4283896656184971, 0.0654001119267702, 1.1731129536153153, 0.5266319998114539, 1.2258224936038002, -0.12688134771141724, 0.17603352040861653, 0.10384825053801694, 2.456431257885204, 1.7442721424143217, 0.31197998165093543, 1.649616566468349, 1.5085017726024517, 1.4393884475536527, 2.1369790473537638, 0.3198414434350847, 1.5346003504419548, -0.3254683459733947, 0.9251839152140575, -1.4316405748601717, 0.08247313129525669, 1.0927406836991975, 0.7591184545945047, 0.9885524523474178, 0.038956994171441606, 0.9927075241655323, 0.3938499261889389, 1.4659784812394907, 1.3100588492476435, 3.014711772208164, 1.9795848001550582, 1.5565779017977657, 1.3279594367665446, 2.072789929018194, 1.524265394736741, 1.3245118301561005, 2.351766235483127, -1.064904264221144, 2.123110700853826, 1.6947290976472362, 2.433969667147129, 1.4569264613189485, 0.9364462752531815, 0.9223366197155805, 1.715401297375632, 2.0714372316856653, 1.1401718301627757, 1.6938945731866732, -0.07434219150232191, 0.064758900735712, 2.128805418971508, 0.9786250935154447, 1.5340059689365901, 1.9611115834169626, -0.6033552912511781, -0.0013987453086474755, -0.15830360218326933, 0.9451039715082076, 0.4063700303981228, 1.7547508776591867, 0.22774016016810972, 0.6923820462833576, 1.4628128923949533, 1.5519475809136658, 1.8388268473748162, 1.1414983529583231, 1.7293945494807712, 1.012984874331843, 1.2117937635497509, 0.48523156465232775, 0.2321225606288828, 1.6313932178329376, 2.062390616609129, 2.7403219263727916, 0.671508568150707, 1.3476941823121602, 1.3852395960754258, 2.004590421193086, 0.7572415129264691, 1.461461585075642, 0.9727939574798193, 0.6442985790832872, 0.21197037521948547, 0.4388164706212847, 0.15250921825250652, 1.1384981318119916, 0.1294082188060628, -0.046204539372335596, 0.571420732523709, 1.1312281306833583, 1.1316528859284989, -0.10815970066999947, -1.1984342960846441, 0.3589464274020281, -0.7086084475543339, 0.2159547013905213, -0.5498885534187372, 1.6998166190706305, 0.6333973066170069, 0.3178961882010708, 0.4057571822270476, -0.943678711416043, 0.0845262864376779, 0.8172627252665122, 1.2141536991053616, 0.6455249148175821, -0.18199120660065704, 1.3109444765664826, 0.6262686215230704, 1.541632463149533, 0.7568620977271456, 2.678547122398129, -0.7794131258553767, 2.939856336680486, 0.4516117064119436, 2.1238358347733035, 2.2707038677922267, 0.7695426723915446, -0.08376409489572123, 1.7000307922274984, 1.6368386558568462, 1.6547862761999945, 1.2103757768713652, 1.7693361148887852, 0.7199781208650826, 0.6409844131921998, 1.7453088399229832, 1.904422166729794, -0.31269724266053656, 1.3942510274969138, 2.3797740783110948, 0.5281061306140165, 0.421189757513874 ], "xaxis": "x", "xbingroup": "x", "y": [ 3.1282385335556557, 4.070351447983859, 4.044971641612177, 2.77260882512933, 3.1840904111479684, 2.797531787233325, 3.7427255196490212, 4.539013949432658, 4.416898522348004, 3.4638037228342533, 2.4871874700564733, 3.76633095478069, 2.8696024099170905, 2.9088611582376713, 2.9020823263628315, 1.4827361604497347, 4.061838380675139, 2.729167689502741, 2.2920272579544756, 2.8812805125823484, 3.913378603698461, 2.7303085521979837, 3.277930312652814, 2.113296262547278, 3.2519852959321343, 2.913326089210684, 3.6170340370550917, 3.1093954082075452, 3.2077553511567447, 4.681231929994688, 2.800910383948769, 2.390125318688806, 3.0081022807487803, 2.3286538766812055, 3.4782043305543966, 3.590017904088259, 1.3846851259576687, 2.9488719579582074, 2.747281930028972, 2.7757399592560965, 3.14315262773308, 3.729150463539984, 2.272604514189201, 3.613795386514495, 3.4452290397630603, 4.5472494952885425, 2.246882604138982, 2.5651217892549836, 3.5071235585237956, 2.227157161742794, 4.542242727626207, 3.1649587611590784, 2.814654746438766, 3.8730630455123367, 3.409183945419323, 4.08526101685672, 2.3190982970186624, 2.906148603589161, 2.9274610735252558, 3.2052981868345727, 3.6513088918199132, 2.3448136421414523, 2.607025498792512, 2.83995391967794, 2.4666892975135655, 2.1725871735840077, 4.018465214351547, 3.521212363923993, 2.454759170159876, 4.011390240610069, 2.500471938754235, 3.4022488403009774, 3.0966654750071565, 2.9245444532155904, 3.321783488631805, 2.8730575282962953, 3.6835001396783227, 2.870484238934687, 2.931615244729479, 4.164150404150385, 3.3030522792806263, 2.742349003816946, 2.005529352377435, 4.0023309294120555, 2.1240569432613574, 2.5762411765202344, 1.6064103777219652, 3.44719380968696, 3.6785544924596083, 2.314207642081339, 2.3265416750591434, 3.1544165791197982, 4.8740153398816615, 3.007369378408933, 1.7107980648817582, 2.837093703911082, 3.5473557402215405, 2.7704043344653253, 3.279608738816, 3.346384411390747, 2.52933636082088, 4.034545076085514, 3.366503383926385, 4.337829649342294, 2.172233343425634, 2.5919495640126637, 2.4834739927208243, 4.432106338636501, 3.74887323529349, 3.14028129425762, 3.2439425546031715, 3.6742108777779294, 3.162811521511834, 3.039999505120035, 4.2992603384435615, 2.3812371551823954, 2.755191914662937, 2.4803634008695483, 2.8942240925019354, 2.640143476984384, 3.7183712591305125, 2.1307642836244334, 2.4793758745178582, 3.3490213324330265, 3.6592286155099996, 2.794815795814387, 2.716354015404513, 2.3578282786167266, 2.4354214322988987, 2.6728912902609703, 2.240369153417558, 2.6359891683494654, 3.2271015558889706, 2.248124662271843, 3.2480321287061735, 2.2001625357586856, 3.4004452102136784, 2.6977217917901126, 2.383433791586739, 3.480433646137479, 2.092343788629348, 3.3562275785924385, 3.4423757304610265, 2.9892137410410906, 3.295203500164597, 3.562026694177126, 2.743987644027496, 2.834684771052965, 4.1583923949026715, 1.8485793896271314, 2.167049916102464, 2.554287248846739, 2.7137071070374548, 2.7217934960660095, 3.531866302246744, 3.211313041238663, 3.549817861947939, 3.262848341356853, 2.87719152886365, 3.3056792317707786, 2.8503162199719383, 2.999795120588682, 3.696428994380816, 2.557997374288019, 3.009117514515939, 2.9224650205798337, 2.6953589063166024, 2.68571411757148, 2.932608179967035, 2.8344236536860823, 3.032976260309731, 4.163435659416412, 2.9763065880418, 3.1870998384216094, 2.4023544073788576, 3.125923808781438, 1.6788396885522132, 3.0520129651732737, 3.8946230779397317, 3.0115182817732054, 3.616426516336678, 1.9200974306813938, 4.132969045857365, 3.1737063032493404, 3.4001787286011678, 2.255527680000906, 3.264275217532181, 3.3433191192757215, 3.0265108523493143, 3.133522098374776, 3.037303908226366, 2.181451783408736, 3.157625368019054, 3.325531518897907, 3.4430290038612967, 1.8749266990057036, 3.063879164523096, 2.9791434338429323, 2.1845029262013544, 2.9398782946987883 ], "yaxis": "y", "ybingroup": "y" } ], "layout": { "coloraxis": { "colorbar": { "title": { "text": "count" } }, "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" ] ] }, "legend": { "tracegroupgap": 0 }, "margin": { "t": 60 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "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": "X" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "Y" } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df = data1\n", "fig = px.density_heatmap(df, x=\"X\", y=\"Y\")\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Add a title to your chart by passing a string as the input `title` into the function `density_heatmap`\n", "3. And customise the size of the figure by using the inputs `height` and `width`. Both have to be integers and correspond to the size of the figure in pixels." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "coloraxis": "coloraxis", "hovertemplate": "X=%{x}
Y=%{y}
count=%{z}", "name": "", "type": "histogram2d", "x": [ 2.31712013454836, 0.9955529116690811, 1.5935376172499718, 0.470556383491882, 0.4158541115098898, -0.22167942099963578, 2.580265645305723, 3.9310544147650504, 2.8931706098195393, 0.7275794361740546, 2.0152089110594336, 2.7321084386647634, 1.324552882814132, 0.35025134091154864, 2.650036844272331, 0.17138726836009488, 1.8467812954548124, -0.25978469328708864, 0.20112104181319734, 1.8823185163963756, 1.0778911534705955, 1.491036853022197, 1.2736938497826842, 0.5540013289664579, 2.9060172357014915, -0.2838477734846878, 1.8189725170859496, 2.35418220242837, 1.2663379745732963, 1.5375968602562398, 1.8402136331248191, 0.8786000822702367, 1.5888778426382055, 0.19248465112718183, 0.5384097774666239, 1.0573066963645428, -0.9280367663576994, 2.0876392670005957, 1.339594614146936, 0.37031409099418877, 1.534614406589347, 1.7137536023177005, 0.5791939635283425, 0.750240518284518, 0.5161609767969657, 2.9968955064731797, 0.00820701237511623, 0.9597167346765632, 1.2639629095967337, 2.023902862326633, 1.74179617867757, 0.5019587874992837, 2.25305796323564, 2.7328107074969332, 2.367176612405366, 1.9305001326073732, 0.36451730845511454, 0.5105867334812165, 0.3302935715034603, 0.6452846847414433, 1.084982000292835, -0.3958921857473203, 1.6637282735289345, -1.3237533839282252, -0.01574845416352688, 1.1175169016700064, 1.5552121293363905, 1.4283896656184971, 0.0654001119267702, 1.1731129536153153, 0.5266319998114539, 1.2258224936038002, -0.12688134771141724, 0.17603352040861653, 0.10384825053801694, 2.456431257885204, 1.7442721424143217, 0.31197998165093543, 1.649616566468349, 1.5085017726024517, 1.4393884475536527, 2.1369790473537638, 0.3198414434350847, 1.5346003504419548, -0.3254683459733947, 0.9251839152140575, -1.4316405748601717, 0.08247313129525669, 1.0927406836991975, 0.7591184545945047, 0.9885524523474178, 0.038956994171441606, 0.9927075241655323, 0.3938499261889389, 1.4659784812394907, 1.3100588492476435, 3.014711772208164, 1.9795848001550582, 1.5565779017977657, 1.3279594367665446, 2.072789929018194, 1.524265394736741, 1.3245118301561005, 2.351766235483127, -1.064904264221144, 2.123110700853826, 1.6947290976472362, 2.433969667147129, 1.4569264613189485, 0.9364462752531815, 0.9223366197155805, 1.715401297375632, 2.0714372316856653, 1.1401718301627757, 1.6938945731866732, -0.07434219150232191, 0.064758900735712, 2.128805418971508, 0.9786250935154447, 1.5340059689365901, 1.9611115834169626, -0.6033552912511781, -0.0013987453086474755, -0.15830360218326933, 0.9451039715082076, 0.4063700303981228, 1.7547508776591867, 0.22774016016810972, 0.6923820462833576, 1.4628128923949533, 1.5519475809136658, 1.8388268473748162, 1.1414983529583231, 1.7293945494807712, 1.012984874331843, 1.2117937635497509, 0.48523156465232775, 0.2321225606288828, 1.6313932178329376, 2.062390616609129, 2.7403219263727916, 0.671508568150707, 1.3476941823121602, 1.3852395960754258, 2.004590421193086, 0.7572415129264691, 1.461461585075642, 0.9727939574798193, 0.6442985790832872, 0.21197037521948547, 0.4388164706212847, 0.15250921825250652, 1.1384981318119916, 0.1294082188060628, -0.046204539372335596, 0.571420732523709, 1.1312281306833583, 1.1316528859284989, -0.10815970066999947, -1.1984342960846441, 0.3589464274020281, -0.7086084475543339, 0.2159547013905213, -0.5498885534187372, 1.6998166190706305, 0.6333973066170069, 0.3178961882010708, 0.4057571822270476, -0.943678711416043, 0.0845262864376779, 0.8172627252665122, 1.2141536991053616, 0.6455249148175821, -0.18199120660065704, 1.3109444765664826, 0.6262686215230704, 1.541632463149533, 0.7568620977271456, 2.678547122398129, -0.7794131258553767, 2.939856336680486, 0.4516117064119436, 2.1238358347733035, 2.2707038677922267, 0.7695426723915446, -0.08376409489572123, 1.7000307922274984, 1.6368386558568462, 1.6547862761999945, 1.2103757768713652, 1.7693361148887852, 0.7199781208650826, 0.6409844131921998, 1.7453088399229832, 1.904422166729794, -0.31269724266053656, 1.3942510274969138, 2.3797740783110948, 0.5281061306140165, 0.421189757513874 ], "xaxis": "x", "xbingroup": "x", "y": [ 3.1282385335556557, 4.070351447983859, 4.044971641612177, 2.77260882512933, 3.1840904111479684, 2.797531787233325, 3.7427255196490212, 4.539013949432658, 4.416898522348004, 3.4638037228342533, 2.4871874700564733, 3.76633095478069, 2.8696024099170905, 2.9088611582376713, 2.9020823263628315, 1.4827361604497347, 4.061838380675139, 2.729167689502741, 2.2920272579544756, 2.8812805125823484, 3.913378603698461, 2.7303085521979837, 3.277930312652814, 2.113296262547278, 3.2519852959321343, 2.913326089210684, 3.6170340370550917, 3.1093954082075452, 3.2077553511567447, 4.681231929994688, 2.800910383948769, 2.390125318688806, 3.0081022807487803, 2.3286538766812055, 3.4782043305543966, 3.590017904088259, 1.3846851259576687, 2.9488719579582074, 2.747281930028972, 2.7757399592560965, 3.14315262773308, 3.729150463539984, 2.272604514189201, 3.613795386514495, 3.4452290397630603, 4.5472494952885425, 2.246882604138982, 2.5651217892549836, 3.5071235585237956, 2.227157161742794, 4.542242727626207, 3.1649587611590784, 2.814654746438766, 3.8730630455123367, 3.409183945419323, 4.08526101685672, 2.3190982970186624, 2.906148603589161, 2.9274610735252558, 3.2052981868345727, 3.6513088918199132, 2.3448136421414523, 2.607025498792512, 2.83995391967794, 2.4666892975135655, 2.1725871735840077, 4.018465214351547, 3.521212363923993, 2.454759170159876, 4.011390240610069, 2.500471938754235, 3.4022488403009774, 3.0966654750071565, 2.9245444532155904, 3.321783488631805, 2.8730575282962953, 3.6835001396783227, 2.870484238934687, 2.931615244729479, 4.164150404150385, 3.3030522792806263, 2.742349003816946, 2.005529352377435, 4.0023309294120555, 2.1240569432613574, 2.5762411765202344, 1.6064103777219652, 3.44719380968696, 3.6785544924596083, 2.314207642081339, 2.3265416750591434, 3.1544165791197982, 4.8740153398816615, 3.007369378408933, 1.7107980648817582, 2.837093703911082, 3.5473557402215405, 2.7704043344653253, 3.279608738816, 3.346384411390747, 2.52933636082088, 4.034545076085514, 3.366503383926385, 4.337829649342294, 2.172233343425634, 2.5919495640126637, 2.4834739927208243, 4.432106338636501, 3.74887323529349, 3.14028129425762, 3.2439425546031715, 3.6742108777779294, 3.162811521511834, 3.039999505120035, 4.2992603384435615, 2.3812371551823954, 2.755191914662937, 2.4803634008695483, 2.8942240925019354, 2.640143476984384, 3.7183712591305125, 2.1307642836244334, 2.4793758745178582, 3.3490213324330265, 3.6592286155099996, 2.794815795814387, 2.716354015404513, 2.3578282786167266, 2.4354214322988987, 2.6728912902609703, 2.240369153417558, 2.6359891683494654, 3.2271015558889706, 2.248124662271843, 3.2480321287061735, 2.2001625357586856, 3.4004452102136784, 2.6977217917901126, 2.383433791586739, 3.480433646137479, 2.092343788629348, 3.3562275785924385, 3.4423757304610265, 2.9892137410410906, 3.295203500164597, 3.562026694177126, 2.743987644027496, 2.834684771052965, 4.1583923949026715, 1.8485793896271314, 2.167049916102464, 2.554287248846739, 2.7137071070374548, 2.7217934960660095, 3.531866302246744, 3.211313041238663, 3.549817861947939, 3.262848341356853, 2.87719152886365, 3.3056792317707786, 2.8503162199719383, 2.999795120588682, 3.696428994380816, 2.557997374288019, 3.009117514515939, 2.9224650205798337, 2.6953589063166024, 2.68571411757148, 2.932608179967035, 2.8344236536860823, 3.032976260309731, 4.163435659416412, 2.9763065880418, 3.1870998384216094, 2.4023544073788576, 3.125923808781438, 1.6788396885522132, 3.0520129651732737, 3.8946230779397317, 3.0115182817732054, 3.616426516336678, 1.9200974306813938, 4.132969045857365, 3.1737063032493404, 3.4001787286011678, 2.255527680000906, 3.264275217532181, 3.3433191192757215, 3.0265108523493143, 3.133522098374776, 3.037303908226366, 2.181451783408736, 3.157625368019054, 3.325531518897907, 3.4430290038612967, 1.8749266990057036, 3.063879164523096, 2.9791434338429323, 2.1845029262013544, 2.9398782946987883 ], "yaxis": "y", "ybingroup": "y" } ], "layout": { "coloraxis": { "colorbar": { "title": { "text": "count" } }, "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" ] ] }, "height": 500, "legend": { "tracegroupgap": 0 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "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 } } }, "title": { "text": "Sample from a Bi-variate Normal Distribution" }, "width": 800, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "X" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "Y" } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.density_heatmap(df, x=\"X\", y=\"Y\",\n", " height = 500, width = 800,\n", " title='Sample from a Bi-variate Normal Distribution')\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4. Just as in the case of simple histograms, we can display 2-D histograms in density scale by setting the input `histnorm` as `'probability density'`" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "coloraxis": "coloraxis", "histnorm": "probability density", "hovertemplate": "X=%{x}
Y=%{y}
probability density=%{z}", "name": "", "type": "histogram2d", "x": [ 2.31712013454836, 0.9955529116690811, 1.5935376172499718, 0.470556383491882, 0.4158541115098898, -0.22167942099963578, 2.580265645305723, 3.9310544147650504, 2.8931706098195393, 0.7275794361740546, 2.0152089110594336, 2.7321084386647634, 1.324552882814132, 0.35025134091154864, 2.650036844272331, 0.17138726836009488, 1.8467812954548124, -0.25978469328708864, 0.20112104181319734, 1.8823185163963756, 1.0778911534705955, 1.491036853022197, 1.2736938497826842, 0.5540013289664579, 2.9060172357014915, -0.2838477734846878, 1.8189725170859496, 2.35418220242837, 1.2663379745732963, 1.5375968602562398, 1.8402136331248191, 0.8786000822702367, 1.5888778426382055, 0.19248465112718183, 0.5384097774666239, 1.0573066963645428, -0.9280367663576994, 2.0876392670005957, 1.339594614146936, 0.37031409099418877, 1.534614406589347, 1.7137536023177005, 0.5791939635283425, 0.750240518284518, 0.5161609767969657, 2.9968955064731797, 0.00820701237511623, 0.9597167346765632, 1.2639629095967337, 2.023902862326633, 1.74179617867757, 0.5019587874992837, 2.25305796323564, 2.7328107074969332, 2.367176612405366, 1.9305001326073732, 0.36451730845511454, 0.5105867334812165, 0.3302935715034603, 0.6452846847414433, 1.084982000292835, -0.3958921857473203, 1.6637282735289345, -1.3237533839282252, -0.01574845416352688, 1.1175169016700064, 1.5552121293363905, 1.4283896656184971, 0.0654001119267702, 1.1731129536153153, 0.5266319998114539, 1.2258224936038002, -0.12688134771141724, 0.17603352040861653, 0.10384825053801694, 2.456431257885204, 1.7442721424143217, 0.31197998165093543, 1.649616566468349, 1.5085017726024517, 1.4393884475536527, 2.1369790473537638, 0.3198414434350847, 1.5346003504419548, -0.3254683459733947, 0.9251839152140575, -1.4316405748601717, 0.08247313129525669, 1.0927406836991975, 0.7591184545945047, 0.9885524523474178, 0.038956994171441606, 0.9927075241655323, 0.3938499261889389, 1.4659784812394907, 1.3100588492476435, 3.014711772208164, 1.9795848001550582, 1.5565779017977657, 1.3279594367665446, 2.072789929018194, 1.524265394736741, 1.3245118301561005, 2.351766235483127, -1.064904264221144, 2.123110700853826, 1.6947290976472362, 2.433969667147129, 1.4569264613189485, 0.9364462752531815, 0.9223366197155805, 1.715401297375632, 2.0714372316856653, 1.1401718301627757, 1.6938945731866732, -0.07434219150232191, 0.064758900735712, 2.128805418971508, 0.9786250935154447, 1.5340059689365901, 1.9611115834169626, -0.6033552912511781, -0.0013987453086474755, -0.15830360218326933, 0.9451039715082076, 0.4063700303981228, 1.7547508776591867, 0.22774016016810972, 0.6923820462833576, 1.4628128923949533, 1.5519475809136658, 1.8388268473748162, 1.1414983529583231, 1.7293945494807712, 1.012984874331843, 1.2117937635497509, 0.48523156465232775, 0.2321225606288828, 1.6313932178329376, 2.062390616609129, 2.7403219263727916, 0.671508568150707, 1.3476941823121602, 1.3852395960754258, 2.004590421193086, 0.7572415129264691, 1.461461585075642, 0.9727939574798193, 0.6442985790832872, 0.21197037521948547, 0.4388164706212847, 0.15250921825250652, 1.1384981318119916, 0.1294082188060628, -0.046204539372335596, 0.571420732523709, 1.1312281306833583, 1.1316528859284989, -0.10815970066999947, -1.1984342960846441, 0.3589464274020281, -0.7086084475543339, 0.2159547013905213, -0.5498885534187372, 1.6998166190706305, 0.6333973066170069, 0.3178961882010708, 0.4057571822270476, -0.943678711416043, 0.0845262864376779, 0.8172627252665122, 1.2141536991053616, 0.6455249148175821, -0.18199120660065704, 1.3109444765664826, 0.6262686215230704, 1.541632463149533, 0.7568620977271456, 2.678547122398129, -0.7794131258553767, 2.939856336680486, 0.4516117064119436, 2.1238358347733035, 2.2707038677922267, 0.7695426723915446, -0.08376409489572123, 1.7000307922274984, 1.6368386558568462, 1.6547862761999945, 1.2103757768713652, 1.7693361148887852, 0.7199781208650826, 0.6409844131921998, 1.7453088399229832, 1.904422166729794, -0.31269724266053656, 1.3942510274969138, 2.3797740783110948, 0.5281061306140165, 0.421189757513874 ], "xaxis": "x", "xbingroup": "x", "y": [ 3.1282385335556557, 4.070351447983859, 4.044971641612177, 2.77260882512933, 3.1840904111479684, 2.797531787233325, 3.7427255196490212, 4.539013949432658, 4.416898522348004, 3.4638037228342533, 2.4871874700564733, 3.76633095478069, 2.8696024099170905, 2.9088611582376713, 2.9020823263628315, 1.4827361604497347, 4.061838380675139, 2.729167689502741, 2.2920272579544756, 2.8812805125823484, 3.913378603698461, 2.7303085521979837, 3.277930312652814, 2.113296262547278, 3.2519852959321343, 2.913326089210684, 3.6170340370550917, 3.1093954082075452, 3.2077553511567447, 4.681231929994688, 2.800910383948769, 2.390125318688806, 3.0081022807487803, 2.3286538766812055, 3.4782043305543966, 3.590017904088259, 1.3846851259576687, 2.9488719579582074, 2.747281930028972, 2.7757399592560965, 3.14315262773308, 3.729150463539984, 2.272604514189201, 3.613795386514495, 3.4452290397630603, 4.5472494952885425, 2.246882604138982, 2.5651217892549836, 3.5071235585237956, 2.227157161742794, 4.542242727626207, 3.1649587611590784, 2.814654746438766, 3.8730630455123367, 3.409183945419323, 4.08526101685672, 2.3190982970186624, 2.906148603589161, 2.9274610735252558, 3.2052981868345727, 3.6513088918199132, 2.3448136421414523, 2.607025498792512, 2.83995391967794, 2.4666892975135655, 2.1725871735840077, 4.018465214351547, 3.521212363923993, 2.454759170159876, 4.011390240610069, 2.500471938754235, 3.4022488403009774, 3.0966654750071565, 2.9245444532155904, 3.321783488631805, 2.8730575282962953, 3.6835001396783227, 2.870484238934687, 2.931615244729479, 4.164150404150385, 3.3030522792806263, 2.742349003816946, 2.005529352377435, 4.0023309294120555, 2.1240569432613574, 2.5762411765202344, 1.6064103777219652, 3.44719380968696, 3.6785544924596083, 2.314207642081339, 2.3265416750591434, 3.1544165791197982, 4.8740153398816615, 3.007369378408933, 1.7107980648817582, 2.837093703911082, 3.5473557402215405, 2.7704043344653253, 3.279608738816, 3.346384411390747, 2.52933636082088, 4.034545076085514, 3.366503383926385, 4.337829649342294, 2.172233343425634, 2.5919495640126637, 2.4834739927208243, 4.432106338636501, 3.74887323529349, 3.14028129425762, 3.2439425546031715, 3.6742108777779294, 3.162811521511834, 3.039999505120035, 4.2992603384435615, 2.3812371551823954, 2.755191914662937, 2.4803634008695483, 2.8942240925019354, 2.640143476984384, 3.7183712591305125, 2.1307642836244334, 2.4793758745178582, 3.3490213324330265, 3.6592286155099996, 2.794815795814387, 2.716354015404513, 2.3578282786167266, 2.4354214322988987, 2.6728912902609703, 2.240369153417558, 2.6359891683494654, 3.2271015558889706, 2.248124662271843, 3.2480321287061735, 2.2001625357586856, 3.4004452102136784, 2.6977217917901126, 2.383433791586739, 3.480433646137479, 2.092343788629348, 3.3562275785924385, 3.4423757304610265, 2.9892137410410906, 3.295203500164597, 3.562026694177126, 2.743987644027496, 2.834684771052965, 4.1583923949026715, 1.8485793896271314, 2.167049916102464, 2.554287248846739, 2.7137071070374548, 2.7217934960660095, 3.531866302246744, 3.211313041238663, 3.549817861947939, 3.262848341356853, 2.87719152886365, 3.3056792317707786, 2.8503162199719383, 2.999795120588682, 3.696428994380816, 2.557997374288019, 3.009117514515939, 2.9224650205798337, 2.6953589063166024, 2.68571411757148, 2.932608179967035, 2.8344236536860823, 3.032976260309731, 4.163435659416412, 2.9763065880418, 3.1870998384216094, 2.4023544073788576, 3.125923808781438, 1.6788396885522132, 3.0520129651732737, 3.8946230779397317, 3.0115182817732054, 3.616426516336678, 1.9200974306813938, 4.132969045857365, 3.1737063032493404, 3.4001787286011678, 2.255527680000906, 3.264275217532181, 3.3433191192757215, 3.0265108523493143, 3.133522098374776, 3.037303908226366, 2.181451783408736, 3.157625368019054, 3.325531518897907, 3.4430290038612967, 1.8749266990057036, 3.063879164523096, 2.9791434338429323, 2.1845029262013544, 2.9398782946987883 ], "yaxis": "y", "ybingroup": "y" } ], "layout": { "coloraxis": { "colorbar": { "title": { "text": "probability density" } }, "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" ] ] }, "height": 500, "legend": { "tracegroupgap": 0 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "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 } } }, "title": { "text": "Sample from a Bi-variate Normal Distribution" }, "width": 800, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "X" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "Y" } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.density_heatmap(df, x=\"X\", y=\"Y\",\n", " histnorm='probability density',\n", " height = 500, width = 800,\n", " title='Sample from a Bi-variate Normal Distribution')\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "5. Customize the number of bins in both axys by using the inputs `nbinsx` and `nbinsy`" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "coloraxis": "coloraxis", "histnorm": "probability density", "hovertemplate": "X=%{x}
Y=%{y}
probability density=%{z}", "name": "", "nbinsx": 25, "nbinsy": 25, "type": "histogram2d", "x": [ 2.31712013454836, 0.9955529116690811, 1.5935376172499718, 0.470556383491882, 0.4158541115098898, -0.22167942099963578, 2.580265645305723, 3.9310544147650504, 2.8931706098195393, 0.7275794361740546, 2.0152089110594336, 2.7321084386647634, 1.324552882814132, 0.35025134091154864, 2.650036844272331, 0.17138726836009488, 1.8467812954548124, -0.25978469328708864, 0.20112104181319734, 1.8823185163963756, 1.0778911534705955, 1.491036853022197, 1.2736938497826842, 0.5540013289664579, 2.9060172357014915, -0.2838477734846878, 1.8189725170859496, 2.35418220242837, 1.2663379745732963, 1.5375968602562398, 1.8402136331248191, 0.8786000822702367, 1.5888778426382055, 0.19248465112718183, 0.5384097774666239, 1.0573066963645428, -0.9280367663576994, 2.0876392670005957, 1.339594614146936, 0.37031409099418877, 1.534614406589347, 1.7137536023177005, 0.5791939635283425, 0.750240518284518, 0.5161609767969657, 2.9968955064731797, 0.00820701237511623, 0.9597167346765632, 1.2639629095967337, 2.023902862326633, 1.74179617867757, 0.5019587874992837, 2.25305796323564, 2.7328107074969332, 2.367176612405366, 1.9305001326073732, 0.36451730845511454, 0.5105867334812165, 0.3302935715034603, 0.6452846847414433, 1.084982000292835, -0.3958921857473203, 1.6637282735289345, -1.3237533839282252, -0.01574845416352688, 1.1175169016700064, 1.5552121293363905, 1.4283896656184971, 0.0654001119267702, 1.1731129536153153, 0.5266319998114539, 1.2258224936038002, -0.12688134771141724, 0.17603352040861653, 0.10384825053801694, 2.456431257885204, 1.7442721424143217, 0.31197998165093543, 1.649616566468349, 1.5085017726024517, 1.4393884475536527, 2.1369790473537638, 0.3198414434350847, 1.5346003504419548, -0.3254683459733947, 0.9251839152140575, -1.4316405748601717, 0.08247313129525669, 1.0927406836991975, 0.7591184545945047, 0.9885524523474178, 0.038956994171441606, 0.9927075241655323, 0.3938499261889389, 1.4659784812394907, 1.3100588492476435, 3.014711772208164, 1.9795848001550582, 1.5565779017977657, 1.3279594367665446, 2.072789929018194, 1.524265394736741, 1.3245118301561005, 2.351766235483127, -1.064904264221144, 2.123110700853826, 1.6947290976472362, 2.433969667147129, 1.4569264613189485, 0.9364462752531815, 0.9223366197155805, 1.715401297375632, 2.0714372316856653, 1.1401718301627757, 1.6938945731866732, -0.07434219150232191, 0.064758900735712, 2.128805418971508, 0.9786250935154447, 1.5340059689365901, 1.9611115834169626, -0.6033552912511781, -0.0013987453086474755, -0.15830360218326933, 0.9451039715082076, 0.4063700303981228, 1.7547508776591867, 0.22774016016810972, 0.6923820462833576, 1.4628128923949533, 1.5519475809136658, 1.8388268473748162, 1.1414983529583231, 1.7293945494807712, 1.012984874331843, 1.2117937635497509, 0.48523156465232775, 0.2321225606288828, 1.6313932178329376, 2.062390616609129, 2.7403219263727916, 0.671508568150707, 1.3476941823121602, 1.3852395960754258, 2.004590421193086, 0.7572415129264691, 1.461461585075642, 0.9727939574798193, 0.6442985790832872, 0.21197037521948547, 0.4388164706212847, 0.15250921825250652, 1.1384981318119916, 0.1294082188060628, -0.046204539372335596, 0.571420732523709, 1.1312281306833583, 1.1316528859284989, -0.10815970066999947, -1.1984342960846441, 0.3589464274020281, -0.7086084475543339, 0.2159547013905213, -0.5498885534187372, 1.6998166190706305, 0.6333973066170069, 0.3178961882010708, 0.4057571822270476, -0.943678711416043, 0.0845262864376779, 0.8172627252665122, 1.2141536991053616, 0.6455249148175821, -0.18199120660065704, 1.3109444765664826, 0.6262686215230704, 1.541632463149533, 0.7568620977271456, 2.678547122398129, -0.7794131258553767, 2.939856336680486, 0.4516117064119436, 2.1238358347733035, 2.2707038677922267, 0.7695426723915446, -0.08376409489572123, 1.7000307922274984, 1.6368386558568462, 1.6547862761999945, 1.2103757768713652, 1.7693361148887852, 0.7199781208650826, 0.6409844131921998, 1.7453088399229832, 1.904422166729794, -0.31269724266053656, 1.3942510274969138, 2.3797740783110948, 0.5281061306140165, 0.421189757513874 ], "xaxis": "x", "xbingroup": "x", "y": [ 3.1282385335556557, 4.070351447983859, 4.044971641612177, 2.77260882512933, 3.1840904111479684, 2.797531787233325, 3.7427255196490212, 4.539013949432658, 4.416898522348004, 3.4638037228342533, 2.4871874700564733, 3.76633095478069, 2.8696024099170905, 2.9088611582376713, 2.9020823263628315, 1.4827361604497347, 4.061838380675139, 2.729167689502741, 2.2920272579544756, 2.8812805125823484, 3.913378603698461, 2.7303085521979837, 3.277930312652814, 2.113296262547278, 3.2519852959321343, 2.913326089210684, 3.6170340370550917, 3.1093954082075452, 3.2077553511567447, 4.681231929994688, 2.800910383948769, 2.390125318688806, 3.0081022807487803, 2.3286538766812055, 3.4782043305543966, 3.590017904088259, 1.3846851259576687, 2.9488719579582074, 2.747281930028972, 2.7757399592560965, 3.14315262773308, 3.729150463539984, 2.272604514189201, 3.613795386514495, 3.4452290397630603, 4.5472494952885425, 2.246882604138982, 2.5651217892549836, 3.5071235585237956, 2.227157161742794, 4.542242727626207, 3.1649587611590784, 2.814654746438766, 3.8730630455123367, 3.409183945419323, 4.08526101685672, 2.3190982970186624, 2.906148603589161, 2.9274610735252558, 3.2052981868345727, 3.6513088918199132, 2.3448136421414523, 2.607025498792512, 2.83995391967794, 2.4666892975135655, 2.1725871735840077, 4.018465214351547, 3.521212363923993, 2.454759170159876, 4.011390240610069, 2.500471938754235, 3.4022488403009774, 3.0966654750071565, 2.9245444532155904, 3.321783488631805, 2.8730575282962953, 3.6835001396783227, 2.870484238934687, 2.931615244729479, 4.164150404150385, 3.3030522792806263, 2.742349003816946, 2.005529352377435, 4.0023309294120555, 2.1240569432613574, 2.5762411765202344, 1.6064103777219652, 3.44719380968696, 3.6785544924596083, 2.314207642081339, 2.3265416750591434, 3.1544165791197982, 4.8740153398816615, 3.007369378408933, 1.7107980648817582, 2.837093703911082, 3.5473557402215405, 2.7704043344653253, 3.279608738816, 3.346384411390747, 2.52933636082088, 4.034545076085514, 3.366503383926385, 4.337829649342294, 2.172233343425634, 2.5919495640126637, 2.4834739927208243, 4.432106338636501, 3.74887323529349, 3.14028129425762, 3.2439425546031715, 3.6742108777779294, 3.162811521511834, 3.039999505120035, 4.2992603384435615, 2.3812371551823954, 2.755191914662937, 2.4803634008695483, 2.8942240925019354, 2.640143476984384, 3.7183712591305125, 2.1307642836244334, 2.4793758745178582, 3.3490213324330265, 3.6592286155099996, 2.794815795814387, 2.716354015404513, 2.3578282786167266, 2.4354214322988987, 2.6728912902609703, 2.240369153417558, 2.6359891683494654, 3.2271015558889706, 2.248124662271843, 3.2480321287061735, 2.2001625357586856, 3.4004452102136784, 2.6977217917901126, 2.383433791586739, 3.480433646137479, 2.092343788629348, 3.3562275785924385, 3.4423757304610265, 2.9892137410410906, 3.295203500164597, 3.562026694177126, 2.743987644027496, 2.834684771052965, 4.1583923949026715, 1.8485793896271314, 2.167049916102464, 2.554287248846739, 2.7137071070374548, 2.7217934960660095, 3.531866302246744, 3.211313041238663, 3.549817861947939, 3.262848341356853, 2.87719152886365, 3.3056792317707786, 2.8503162199719383, 2.999795120588682, 3.696428994380816, 2.557997374288019, 3.009117514515939, 2.9224650205798337, 2.6953589063166024, 2.68571411757148, 2.932608179967035, 2.8344236536860823, 3.032976260309731, 4.163435659416412, 2.9763065880418, 3.1870998384216094, 2.4023544073788576, 3.125923808781438, 1.6788396885522132, 3.0520129651732737, 3.8946230779397317, 3.0115182817732054, 3.616426516336678, 1.9200974306813938, 4.132969045857365, 3.1737063032493404, 3.4001787286011678, 2.255527680000906, 3.264275217532181, 3.3433191192757215, 3.0265108523493143, 3.133522098374776, 3.037303908226366, 2.181451783408736, 3.157625368019054, 3.325531518897907, 3.4430290038612967, 1.8749266990057036, 3.063879164523096, 2.9791434338429323, 2.1845029262013544, 2.9398782946987883 ], "yaxis": "y", "ybingroup": "y" } ], "layout": { "coloraxis": { "colorbar": { "title": { "text": "probability density" } }, "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" ] ] }, "height": 500, "legend": { "tracegroupgap": 0 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "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 } } }, "title": { "text": "Sample from a Bi-variate Normal Distribution" }, "width": 800, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "X" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "Y" } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.density_heatmap(df, x=\"X\", y=\"Y\",\n", " nbinsx= 25,\n", " nbinsy=25,\n", " histnorm='probability density',\n", " height = 500, width = 800,\n", " title='Sample from a Bi-variate Normal Distribution')\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "6. Customise the color of the bars using the input `color_continuous_scale` as follows" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "coloraxis": "coloraxis", "histnorm": "probability density", "hovertemplate": "X=%{x}
Y=%{y}
probability density=%{z}", "name": "", "nbinsx": 25, "nbinsy": 25, "type": "histogram2d", "x": [ 2.31712013454836, 0.9955529116690811, 1.5935376172499718, 0.470556383491882, 0.4158541115098898, -0.22167942099963578, 2.580265645305723, 3.9310544147650504, 2.8931706098195393, 0.7275794361740546, 2.0152089110594336, 2.7321084386647634, 1.324552882814132, 0.35025134091154864, 2.650036844272331, 0.17138726836009488, 1.8467812954548124, -0.25978469328708864, 0.20112104181319734, 1.8823185163963756, 1.0778911534705955, 1.491036853022197, 1.2736938497826842, 0.5540013289664579, 2.9060172357014915, -0.2838477734846878, 1.8189725170859496, 2.35418220242837, 1.2663379745732963, 1.5375968602562398, 1.8402136331248191, 0.8786000822702367, 1.5888778426382055, 0.19248465112718183, 0.5384097774666239, 1.0573066963645428, -0.9280367663576994, 2.0876392670005957, 1.339594614146936, 0.37031409099418877, 1.534614406589347, 1.7137536023177005, 0.5791939635283425, 0.750240518284518, 0.5161609767969657, 2.9968955064731797, 0.00820701237511623, 0.9597167346765632, 1.2639629095967337, 2.023902862326633, 1.74179617867757, 0.5019587874992837, 2.25305796323564, 2.7328107074969332, 2.367176612405366, 1.9305001326073732, 0.36451730845511454, 0.5105867334812165, 0.3302935715034603, 0.6452846847414433, 1.084982000292835, -0.3958921857473203, 1.6637282735289345, -1.3237533839282252, -0.01574845416352688, 1.1175169016700064, 1.5552121293363905, 1.4283896656184971, 0.0654001119267702, 1.1731129536153153, 0.5266319998114539, 1.2258224936038002, -0.12688134771141724, 0.17603352040861653, 0.10384825053801694, 2.456431257885204, 1.7442721424143217, 0.31197998165093543, 1.649616566468349, 1.5085017726024517, 1.4393884475536527, 2.1369790473537638, 0.3198414434350847, 1.5346003504419548, -0.3254683459733947, 0.9251839152140575, -1.4316405748601717, 0.08247313129525669, 1.0927406836991975, 0.7591184545945047, 0.9885524523474178, 0.038956994171441606, 0.9927075241655323, 0.3938499261889389, 1.4659784812394907, 1.3100588492476435, 3.014711772208164, 1.9795848001550582, 1.5565779017977657, 1.3279594367665446, 2.072789929018194, 1.524265394736741, 1.3245118301561005, 2.351766235483127, -1.064904264221144, 2.123110700853826, 1.6947290976472362, 2.433969667147129, 1.4569264613189485, 0.9364462752531815, 0.9223366197155805, 1.715401297375632, 2.0714372316856653, 1.1401718301627757, 1.6938945731866732, -0.07434219150232191, 0.064758900735712, 2.128805418971508, 0.9786250935154447, 1.5340059689365901, 1.9611115834169626, -0.6033552912511781, -0.0013987453086474755, -0.15830360218326933, 0.9451039715082076, 0.4063700303981228, 1.7547508776591867, 0.22774016016810972, 0.6923820462833576, 1.4628128923949533, 1.5519475809136658, 1.8388268473748162, 1.1414983529583231, 1.7293945494807712, 1.012984874331843, 1.2117937635497509, 0.48523156465232775, 0.2321225606288828, 1.6313932178329376, 2.062390616609129, 2.7403219263727916, 0.671508568150707, 1.3476941823121602, 1.3852395960754258, 2.004590421193086, 0.7572415129264691, 1.461461585075642, 0.9727939574798193, 0.6442985790832872, 0.21197037521948547, 0.4388164706212847, 0.15250921825250652, 1.1384981318119916, 0.1294082188060628, -0.046204539372335596, 0.571420732523709, 1.1312281306833583, 1.1316528859284989, -0.10815970066999947, -1.1984342960846441, 0.3589464274020281, -0.7086084475543339, 0.2159547013905213, -0.5498885534187372, 1.6998166190706305, 0.6333973066170069, 0.3178961882010708, 0.4057571822270476, -0.943678711416043, 0.0845262864376779, 0.8172627252665122, 1.2141536991053616, 0.6455249148175821, -0.18199120660065704, 1.3109444765664826, 0.6262686215230704, 1.541632463149533, 0.7568620977271456, 2.678547122398129, -0.7794131258553767, 2.939856336680486, 0.4516117064119436, 2.1238358347733035, 2.2707038677922267, 0.7695426723915446, -0.08376409489572123, 1.7000307922274984, 1.6368386558568462, 1.6547862761999945, 1.2103757768713652, 1.7693361148887852, 0.7199781208650826, 0.6409844131921998, 1.7453088399229832, 1.904422166729794, -0.31269724266053656, 1.3942510274969138, 2.3797740783110948, 0.5281061306140165, 0.421189757513874 ], "xaxis": "x", "xbingroup": "x", "y": [ 3.1282385335556557, 4.070351447983859, 4.044971641612177, 2.77260882512933, 3.1840904111479684, 2.797531787233325, 3.7427255196490212, 4.539013949432658, 4.416898522348004, 3.4638037228342533, 2.4871874700564733, 3.76633095478069, 2.8696024099170905, 2.9088611582376713, 2.9020823263628315, 1.4827361604497347, 4.061838380675139, 2.729167689502741, 2.2920272579544756, 2.8812805125823484, 3.913378603698461, 2.7303085521979837, 3.277930312652814, 2.113296262547278, 3.2519852959321343, 2.913326089210684, 3.6170340370550917, 3.1093954082075452, 3.2077553511567447, 4.681231929994688, 2.800910383948769, 2.390125318688806, 3.0081022807487803, 2.3286538766812055, 3.4782043305543966, 3.590017904088259, 1.3846851259576687, 2.9488719579582074, 2.747281930028972, 2.7757399592560965, 3.14315262773308, 3.729150463539984, 2.272604514189201, 3.613795386514495, 3.4452290397630603, 4.5472494952885425, 2.246882604138982, 2.5651217892549836, 3.5071235585237956, 2.227157161742794, 4.542242727626207, 3.1649587611590784, 2.814654746438766, 3.8730630455123367, 3.409183945419323, 4.08526101685672, 2.3190982970186624, 2.906148603589161, 2.9274610735252558, 3.2052981868345727, 3.6513088918199132, 2.3448136421414523, 2.607025498792512, 2.83995391967794, 2.4666892975135655, 2.1725871735840077, 4.018465214351547, 3.521212363923993, 2.454759170159876, 4.011390240610069, 2.500471938754235, 3.4022488403009774, 3.0966654750071565, 2.9245444532155904, 3.321783488631805, 2.8730575282962953, 3.6835001396783227, 2.870484238934687, 2.931615244729479, 4.164150404150385, 3.3030522792806263, 2.742349003816946, 2.005529352377435, 4.0023309294120555, 2.1240569432613574, 2.5762411765202344, 1.6064103777219652, 3.44719380968696, 3.6785544924596083, 2.314207642081339, 2.3265416750591434, 3.1544165791197982, 4.8740153398816615, 3.007369378408933, 1.7107980648817582, 2.837093703911082, 3.5473557402215405, 2.7704043344653253, 3.279608738816, 3.346384411390747, 2.52933636082088, 4.034545076085514, 3.366503383926385, 4.337829649342294, 2.172233343425634, 2.5919495640126637, 2.4834739927208243, 4.432106338636501, 3.74887323529349, 3.14028129425762, 3.2439425546031715, 3.6742108777779294, 3.162811521511834, 3.039999505120035, 4.2992603384435615, 2.3812371551823954, 2.755191914662937, 2.4803634008695483, 2.8942240925019354, 2.640143476984384, 3.7183712591305125, 2.1307642836244334, 2.4793758745178582, 3.3490213324330265, 3.6592286155099996, 2.794815795814387, 2.716354015404513, 2.3578282786167266, 2.4354214322988987, 2.6728912902609703, 2.240369153417558, 2.6359891683494654, 3.2271015558889706, 2.248124662271843, 3.2480321287061735, 2.2001625357586856, 3.4004452102136784, 2.6977217917901126, 2.383433791586739, 3.480433646137479, 2.092343788629348, 3.3562275785924385, 3.4423757304610265, 2.9892137410410906, 3.295203500164597, 3.562026694177126, 2.743987644027496, 2.834684771052965, 4.1583923949026715, 1.8485793896271314, 2.167049916102464, 2.554287248846739, 2.7137071070374548, 2.7217934960660095, 3.531866302246744, 3.211313041238663, 3.549817861947939, 3.262848341356853, 2.87719152886365, 3.3056792317707786, 2.8503162199719383, 2.999795120588682, 3.696428994380816, 2.557997374288019, 3.009117514515939, 2.9224650205798337, 2.6953589063166024, 2.68571411757148, 2.932608179967035, 2.8344236536860823, 3.032976260309731, 4.163435659416412, 2.9763065880418, 3.1870998384216094, 2.4023544073788576, 3.125923808781438, 1.6788396885522132, 3.0520129651732737, 3.8946230779397317, 3.0115182817732054, 3.616426516336678, 1.9200974306813938, 4.132969045857365, 3.1737063032493404, 3.4001787286011678, 2.255527680000906, 3.264275217532181, 3.3433191192757215, 3.0265108523493143, 3.133522098374776, 3.037303908226366, 2.181451783408736, 3.157625368019054, 3.325531518897907, 3.4430290038612967, 1.8749266990057036, 3.063879164523096, 2.9791434338429323, 2.1845029262013544, 2.9398782946987883 ], "yaxis": "y", "ybingroup": "y" } ], "layout": { "coloraxis": { "colorbar": { "title": { "text": "probability density" } }, "colorscale": [ [ 0, "#440154" ], [ 0.1111111111111111, "#482878" ], [ 0.2222222222222222, "#3e4989" ], [ 0.3333333333333333, "#31688e" ], [ 0.4444444444444444, "#26828e" ], [ 0.5555555555555556, "#1f9e89" ], [ 0.6666666666666666, "#35b779" ], [ 0.7777777777777778, "#6ece58" ], [ 0.8888888888888888, "#b5de2b" ], [ 1, "#fde725" ] ] }, "height": 500, "legend": { "tracegroupgap": 0 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "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": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "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 } } }, "title": { "text": "Sample from a Bi-variate Normal Distribution" }, "width": 800, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "X" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "Y" } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.density_heatmap(df, x=\"X\", y=\"Y\",\n", " color_continuous_scale=\"Viridis\",\n", " nbinsx= 25,\n", " nbinsy=25,\n", " histnorm='probability density',\n", " height = 500, width = 800,\n", " title='Sample from a Bi-variate Normal Distribution')\n", "fig.show()" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.11.4" } }, "nbformat": 4, "nbformat_minor": 2 }