{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating Icicle Charts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Icicle charts are a hierarchical data visualization technique that displays relationships within nested categories using a stacked rectangular layout. Each layer of the hierarchy is represented by a horizontal segment, with the root node (or top-level category) placed at the top and subsequent layers branching downward. The width of each segment reflects a quantitative value, such as size or frequency, making it easy to compare the proportions of different categories within the hierarchy. \n", "\n", "Icicle charts are particularly useful when visualizing hierarchical data with multiple levels, such as organizational structures, file systems, or budget breakdowns. Their linear design allows for straightforward reading, as users can follow the hierarchy from top to bottom without the visual distortions that can occur in circular layouts like sunburst charts. This makes icicle charts well-suited for scenarios where precision and clarity in hierarchical relationships are paramount. Additionally, the rectangular format is space-efficient and can be easier to implement and interpret in digital dashboards or printed reports.\n", "\n", "However, icicle charts should be avoided when the hierarchy is overly complex or the dataset contains too many branches at each level. This can lead to clutter and make the chart difficult to read, especially if the segment widths become too narrow to display labels or meaningful comparisons. They are also less visually engaging than alternative representations like sunburst charts or tree maps, which might be preferred for presentations or storytelling. To maximize their effectiveness, icicle charts should be used when the focus is on hierarchical structure and precise proportions, rather than aesthetics or high-level overviews." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting ready" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "df1 = pd.DataFrame(dict(Activity=[\"My Goals\", \"Health\", \"Career\", \"Personal\", \"Finance\", \n", " \"Exercise\", \"Diet\", \"Sleep\", \n", " \"New Skills\", \"Networking\", \n", " \"Family\", \"Friends\", \n", " \"Investing\", \"Saving\"\n", " ],\n", " Category=[\"\", \"My Goals\", \"My Goals\", \"My Goals\", \"My Goals\", \"Health\", \"Health\", \"Health\", \"Career\", \"Career\", \"Personal\", \"Personal\", \"Finance\", \"Finance\"],\n", " Value=[0, 25, 25, 25, 25, 10, 10, 10, 10, 10, 10, 10, 10, 10]))" ] }, { "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", "
ActivityCategoryValue
0My Goals0
1HealthMy Goals25
2CareerMy Goals25
\n", "
" ], "text/plain": [ " Activity Category Value\n", "0 My Goals 0\n", "1 Health My Goals 25\n", "2 Career My Goals 25" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df1.head(3)" ] }, { "cell_type": "code", "execution_count": 4, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countrycontinentyearlifeExppopgdpPercapiso_alphaiso_num
11AfghanistanAsia200743.82831889923974.580338AFG4
23AlbaniaEurope200776.42336005235937.029526ALB8
35AlgeriaAfrica200772.301333332166223.367465DZA12
\n", "
" ], "text/plain": [ " country continent year lifeExp pop gdpPercap iso_alpha \\\n", "11 Afghanistan Asia 2007 43.828 31889923 974.580338 AFG \n", "23 Albania Europe 2007 76.423 3600523 5937.029526 ALB \n", "35 Algeria Africa 2007 72.301 33333216 6223.367465 DZA \n", "\n", " iso_num \n", "11 4 \n", "23 8 \n", "35 12 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.express as px\n", "df2 = px.data.gapminder().query(\"year == 2007\")\n", "df2.head(3)" ] }, { "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": 5, "metadata": {}, "outputs": [], "source": [ "import plotly.express as px" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Create a minimal icicle chart by calling the function `icicle` from Plotly express and passing the data set `df` as well as the following key arguments:\n", "\n", "- `names`\n", "- `parents`\n", "\n", "In addition, the following extra arguments are specified\n", "\n", "- `height` and `width`\n", "- `title`\n", "\n", "to set the dimensions and the title of our figure." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "domain": { "x": [ 0, 1 ], "y": [ 0, 1 ] }, "hovertemplate": "Activity=%{label}
Category=%{parent}", "labels": [ "My Goals", "Health", "Career", "Personal", "Finance", "Exercise", "Diet", "Sleep", "New Skills", "Networking", "Family", "Friends", "Investing", "Saving" ], "name": "", "parents": [ "", "My Goals", "My Goals", "My Goals", "My Goals", "Health", "Health", "Health", "Career", "Career", "Personal", "Personal", "Finance", "Finance" ], "type": "icicle" } ], "layout": { "height": 600, "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": "Personal Goals 2025" }, "width": 600 } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.icicle(df1, names='Activity',parents='Category',\n", " height=600, width=600,\n", " title='Personal Goals 2025')\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3. Customise the color of the root rectangle by using the method `update_traces` and setting the argument `root_color`. By default the root rectangle is white. Here we are setting the color as `lightgrey` to make it visible against a white background" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "domain": { "x": [ 0, 1 ], "y": [ 0, 1 ] }, "hovertemplate": "Activity=%{label}
Category=%{parent}", "labels": [ "My Goals", "Health", "Career", "Personal", "Finance", "Exercise", "Diet", "Sleep", "New Skills", "Networking", "Family", "Friends", "Investing", "Saving" ], "name": "", "parents": [ "", "My Goals", "My Goals", "My Goals", "My Goals", "Health", "Health", "Health", "Career", "Career", "Personal", "Personal", "Finance", "Finance" ], "root": { "color": "lightgrey" }, "type": "icicle" } ], "layout": { "height": 600, "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": "Personal Goals 2025" }, "width": 600 } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.icicle(df1, names='Activity',parents='Category',\n", " height=600, width=600,\n", " title='Personal Goals 2025')\n", "fig.update_traces(root_color=\"lightgrey\")\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4. Customise the palette used for the inner rectangles by setting the argument `color_discrete_sequence` in the `icicle` function" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "domain": { "x": [ 0, 1 ], "y": [ 0, 1 ] }, "hovertemplate": "Activity=%{label}
Category=%{parent}", "labels": [ "My Goals", "Health", "Career", "Personal", "Finance", "Exercise", "Diet", "Sleep", "New Skills", "Networking", "Family", "Friends", "Investing", "Saving" ], "name": "", "parents": [ "", "My Goals", "My Goals", "My Goals", "My Goals", "Health", "Health", "Health", "Career", "Career", "Personal", "Personal", "Finance", "Finance" ], "root": { "color": "lightgrey" }, "type": "icicle" } ], "layout": { "height": 600, "iciclecolorway": [ "rgb(253, 253, 204)", "rgb(206, 236, 179)", "rgb(156, 219, 165)", "rgb(111, 201, 163)", "rgb(86, 177, 163)", "rgb(76, 153, 160)", "rgb(68, 130, 155)", "rgb(62, 108, 150)", "rgb(62, 82, 143)", "rgb(64, 60, 115)", "rgb(54, 43, 77)", "rgb(39, 26, 44)" ], "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": "Personal Goals 2025" }, "width": 600 } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.icicle(df1, names='Activity',parents='Category',\n", " color_discrete_sequence=px.colors.sequential.deep,\n", " height=600, width=600,\n", " title='Personal Goals 2025')\n", "fig.update_traces(root_color=\"lightgrey\")\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "5. Customise the hover appearance by setting the arguments `hover_name` and `hover_data`" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "customdata": [ [ "My Goals", "" ], [ "Health", "My Goals" ], [ "Career", "My Goals" ], [ "Personal", "My Goals" ], [ "Finance", "My Goals" ], [ "Exercise", "Health" ], [ "Diet", "Health" ], [ "Sleep", "Health" ], [ "New Skills", "Career" ], [ "Networking", "Career" ], [ "Family", "Personal" ], [ "Friends", "Personal" ], [ "Investing", "Finance" ], [ "Saving", "Finance" ] ], "domain": { "x": [ 0, 1 ], "y": [ 0, 1 ] }, "hovertemplate": "%{hovertext}

Activity=%{customdata[0]}", "hovertext": [ "", "My Goals", "My Goals", "My Goals", "My Goals", "Health", "Health", "Health", "Career", "Career", "Personal", "Personal", "Finance", "Finance" ], "labels": [ "My Goals", "Health", "Career", "Personal", "Finance", "Exercise", "Diet", "Sleep", "New Skills", "Networking", "Family", "Friends", "Investing", "Saving" ], "name": "", "parents": [ "", "My Goals", "My Goals", "My Goals", "My Goals", "Health", "Health", "Health", "Career", "Career", "Personal", "Personal", "Finance", "Finance" ], "root": { "color": "lightgrey" }, "type": "icicle" } ], "layout": { "height": 600, "iciclecolorway": [ "rgb(253, 253, 204)", "rgb(206, 236, 179)", "rgb(156, 219, 165)", "rgb(111, 201, 163)", "rgb(86, 177, 163)", "rgb(76, 153, 160)", "rgb(68, 130, 155)", "rgb(62, 108, 150)", "rgb(62, 82, 143)", "rgb(64, 60, 115)", "rgb(54, 43, 77)", "rgb(39, 26, 44)" ], "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": "Personal Goals 2025" }, "width": 600 } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.icicle(df1, names='Activity',parents='Category',\n", " color_discrete_sequence=px.colors.sequential.deep,\n", " hover_name='Category',\n", " hover_data={'Activity':True, 'Category': False},\n", " height=600, width=600,\n", " title='Personal Goals 2025')\n", "fig.update_traces(root_color=\"lightgrey\")\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For our second example, we are going to use the second data set `df2` which contains a subset of the `Gapminder` data. The idea is to visualise both Population and Life Expectancy in the world with particular interest on the comparison between regions.\n", "\n", "1. Create an icicle using the function `icicle` and passing the arguments\n", "\n", " - `path`: this represents the list of columns names or columns of a rectangular dataframe defining the hierarchy of sectors, from root to leaves. Note that we are setting the root as a constant named `World`\n", " - `values`: this is the name of the column (alternatively, you can pass an array object) that is used to specify the size of the rectangles which form the Icicle chart. In our case we pass `pop`" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "branchvalues": "total", "domain": { "x": [ 0, 1 ], "y": [ 0, 1 ] }, "hovertemplate": "labels=%{label}
pop=%{value}
parent=%{parent}
id=%{id}", "ids": [ "World/Asia/Afghanistan", "World/Europe/Albania", "World/Africa/Algeria", "World/Africa/Angola", "World/Americas/Argentina", "World/Oceania/Australia", "World/Europe/Austria", "World/Asia/Bahrain", "World/Asia/Bangladesh", "World/Europe/Belgium", "World/Africa/Benin", "World/Americas/Bolivia", "World/Europe/Bosnia and Herzegovina", "World/Africa/Botswana", "World/Americas/Brazil", "World/Europe/Bulgaria", "World/Africa/Burkina Faso", "World/Africa/Burundi", "World/Asia/Cambodia", "World/Africa/Cameroon", "World/Americas/Canada", "World/Africa/Central African Republic", "World/Africa/Chad", "World/Americas/Chile", "World/Asia/China", "World/Americas/Colombia", "World/Africa/Comoros", "World/Africa/Congo, Dem. Rep.", "World/Africa/Congo, Rep.", "World/Americas/Costa Rica", "World/Africa/Cote d'Ivoire", "World/Europe/Croatia", "World/Americas/Cuba", "World/Europe/Czech Republic", "World/Europe/Denmark", "World/Africa/Djibouti", "World/Americas/Dominican Republic", "World/Americas/Ecuador", "World/Africa/Egypt", "World/Americas/El Salvador", "World/Africa/Equatorial Guinea", "World/Africa/Eritrea", "World/Africa/Ethiopia", "World/Europe/Finland", "World/Europe/France", "World/Africa/Gabon", "World/Africa/Gambia", "World/Europe/Germany", "World/Africa/Ghana", "World/Europe/Greece", "World/Americas/Guatemala", "World/Africa/Guinea", "World/Africa/Guinea-Bissau", "World/Americas/Haiti", "World/Americas/Honduras", "World/Asia/Hong Kong, China", "World/Europe/Hungary", "World/Europe/Iceland", "World/Asia/India", "World/Asia/Indonesia", "World/Asia/Iran", "World/Asia/Iraq", "World/Europe/Ireland", "World/Asia/Israel", "World/Europe/Italy", "World/Americas/Jamaica", "World/Asia/Japan", "World/Asia/Jordan", "World/Africa/Kenya", "World/Asia/Korea, Dem. Rep.", "World/Asia/Korea, Rep.", "World/Asia/Kuwait", "World/Asia/Lebanon", "World/Africa/Lesotho", "World/Africa/Liberia", "World/Africa/Libya", "World/Africa/Madagascar", "World/Africa/Malawi", "World/Asia/Malaysia", "World/Africa/Mali", "World/Africa/Mauritania", "World/Africa/Mauritius", "World/Americas/Mexico", "World/Asia/Mongolia", "World/Europe/Montenegro", "World/Africa/Morocco", "World/Africa/Mozambique", "World/Asia/Myanmar", "World/Africa/Namibia", "World/Asia/Nepal", "World/Europe/Netherlands", "World/Oceania/New Zealand", "World/Americas/Nicaragua", "World/Africa/Niger", "World/Africa/Nigeria", "World/Europe/Norway", "World/Asia/Oman", "World/Asia/Pakistan", "World/Americas/Panama", "World/Americas/Paraguay", "World/Americas/Peru", "World/Asia/Philippines", "World/Europe/Poland", "World/Europe/Portugal", "World/Americas/Puerto Rico", "World/Africa/Reunion", "World/Europe/Romania", "World/Africa/Rwanda", "World/Africa/Sao Tome and Principe", "World/Asia/Saudi Arabia", "World/Africa/Senegal", "World/Europe/Serbia", "World/Africa/Sierra Leone", "World/Asia/Singapore", "World/Europe/Slovak Republic", "World/Europe/Slovenia", "World/Africa/Somalia", "World/Africa/South Africa", "World/Europe/Spain", "World/Asia/Sri Lanka", "World/Africa/Sudan", "World/Africa/Swaziland", "World/Europe/Sweden", "World/Europe/Switzerland", "World/Asia/Syria", "World/Asia/Taiwan", "World/Africa/Tanzania", "World/Asia/Thailand", "World/Africa/Togo", "World/Americas/Trinidad and Tobago", "World/Africa/Tunisia", "World/Europe/Turkey", "World/Africa/Uganda", "World/Europe/United Kingdom", "World/Americas/United States", "World/Americas/Uruguay", "World/Americas/Venezuela", "World/Asia/Vietnam", "World/Asia/West Bank and Gaza", "World/Asia/Yemen, Rep.", "World/Africa/Zambia", "World/Africa/Zimbabwe", "World/Africa", "World/Americas", "World/Asia", "World/Europe", "World/Oceania", "World" ], "labels": [ "Afghanistan", "Albania", "Algeria", "Angola", "Argentina", "Australia", "Austria", "Bahrain", "Bangladesh", "Belgium", "Benin", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo, Dem. Rep.", "Congo, Rep.", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Czech Republic", "Denmark", "Djibouti", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Ethiopia", "Finland", "France", "Gabon", "Gambia", "Germany", "Ghana", "Greece", "Guatemala", "Guinea", "Guinea-Bissau", "Haiti", "Honduras", "Hong Kong, China", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kenya", "Korea, Dem. Rep.", "Korea, Rep.", "Kuwait", "Lebanon", "Lesotho", "Liberia", "Libya", "Madagascar", "Malawi", "Malaysia", "Mali", "Mauritania", "Mauritius", "Mexico", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Panama", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Reunion", "Romania", "Rwanda", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Sierra Leone", "Singapore", "Slovak Republic", "Slovenia", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tanzania", "Thailand", "Togo", "Trinidad and Tobago", "Tunisia", "Turkey", "Uganda", "United Kingdom", "United States", "Uruguay", "Venezuela", "Vietnam", "West Bank and Gaza", "Yemen, Rep.", "Zambia", "Zimbabwe", "Africa", "Americas", "Asia", "Europe", "Oceania", "World" ], "name": "", "parents": [ "World/Asia", "World/Europe", "World/Africa", "World/Africa", "World/Americas", "World/Oceania", "World/Europe", "World/Asia", "World/Asia", "World/Europe", "World/Africa", "World/Americas", "World/Europe", "World/Africa", "World/Americas", "World/Europe", "World/Africa", "World/Africa", "World/Asia", "World/Africa", "World/Americas", "World/Africa", "World/Africa", "World/Americas", "World/Asia", "World/Americas", "World/Africa", "World/Africa", "World/Africa", "World/Americas", "World/Africa", "World/Europe", "World/Americas", "World/Europe", "World/Europe", "World/Africa", "World/Americas", "World/Americas", "World/Africa", "World/Americas", "World/Africa", "World/Africa", "World/Africa", "World/Europe", "World/Europe", "World/Africa", "World/Africa", "World/Europe", "World/Africa", "World/Europe", "World/Americas", "World/Africa", "World/Africa", "World/Americas", "World/Americas", "World/Asia", "World/Europe", "World/Europe", "World/Asia", "World/Asia", "World/Asia", "World/Asia", "World/Europe", "World/Asia", "World/Europe", "World/Americas", "World/Asia", "World/Asia", "World/Africa", "World/Asia", "World/Asia", "World/Asia", "World/Asia", "World/Africa", "World/Africa", "World/Africa", "World/Africa", "World/Africa", "World/Asia", "World/Africa", "World/Africa", "World/Africa", "World/Americas", "World/Asia", "World/Europe", "World/Africa", "World/Africa", "World/Asia", "World/Africa", "World/Asia", "World/Europe", "World/Oceania", "World/Americas", "World/Africa", "World/Africa", "World/Europe", "World/Asia", "World/Asia", "World/Americas", "World/Americas", "World/Americas", "World/Asia", "World/Europe", "World/Europe", "World/Americas", "World/Africa", "World/Europe", "World/Africa", "World/Africa", "World/Asia", "World/Africa", "World/Europe", "World/Africa", "World/Asia", "World/Europe", "World/Europe", "World/Africa", "World/Africa", "World/Europe", "World/Asia", "World/Africa", "World/Africa", "World/Europe", "World/Europe", "World/Asia", "World/Asia", "World/Africa", "World/Asia", "World/Africa", "World/Americas", "World/Africa", "World/Europe", "World/Africa", "World/Europe", "World/Americas", "World/Americas", "World/Americas", "World/Asia", "World/Asia", "World/Asia", "World/Africa", "World/Africa", "World", "World", "World", "World", "World", "" ], "type": "icicle", "values": [ 31889923, 3600523, 33333216, 12420476, 40301927, 20434176, 8199783, 708573, 150448339, 10392226, 8078314, 9119152, 4552198, 1639131, 190010647, 7322858, 14326203, 8390505, 14131858, 17696293, 33390141, 4369038, 10238807, 16284741, 1318683096, 44227550, 710960, 64606759, 3800610, 4133884, 18013409, 4493312, 11416987, 10228744, 5468120, 496374, 9319622, 13755680, 80264543, 6939688, 551201, 4906585, 76511887, 5238460, 61083916, 1454867, 1688359, 82400996, 22873338, 10706290, 12572928, 9947814, 1472041, 8502814, 7483763, 6980412, 9956108, 301931, 1110396331, 223547000, 69453570, 27499638, 4109086, 6426679, 58147733, 2780132, 127467972, 6053193, 35610177, 23301725, 49044790, 2505559, 3921278, 2012649, 3193942, 6036914, 19167654, 13327079, 24821286, 12031795, 3270065, 1250882, 108700891, 2874127, 684736, 33757175, 19951656, 47761980, 2055080, 28901790, 16570613, 4115771, 5675356, 12894865, 135031164, 4627926, 3204897, 169270617, 3242173, 6667147, 28674757, 91077287, 38518241, 10642836, 3942491, 798094, 22276056, 8860588, 199579, 27601038, 12267493, 10150265, 6144562, 4553009, 5447502, 2009245, 9118773, 43997828, 40448191, 20378239, 42292929, 1133066, 9031088, 7554661, 19314747, 23174294, 38139640, 65068149, 5701579, 1056608, 10276158, 71158647, 29170398, 60776238, 301139947, 3447496, 26084662, 85262356, 4018332, 22211743, 11746035, 12311143, 929539692, 898871184, 3811953827, 586098529, 24549947, 6251013179 ] } ], "layout": { "height": 700, "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": "Life Expectancy accross Regions in 2007" }, "width": 700 } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.icicle(df2, path=[px.Constant(\"World\"), 'continent', 'country'], \n", " values='pop',\n", " height=700, width=700,\n", " title='Life Expectancy accross Regions in 2007')\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Use the argument `color` to add an additional dimension to the data through the color of the rectangles. In this case, we are going to associate the color of each rectangle with the Life expectancy of the corresponding country or region. So, we set `color='lifeExp'`. We also use the argument `color_continuous_scale` to set the color palette to be used" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "branchvalues": "total", "customdata": [ [ 43.828 ], [ 76.423 ], [ 72.301 ], [ 42.731 ], [ 75.32 ], [ 81.235 ], [ 79.829 ], [ 75.635 ], [ 64.062 ], [ 79.441 ], [ 56.728 ], [ 65.554 ], [ 74.852 ], [ 50.728 ], [ 72.39 ], [ 73.005 ], [ 52.295 ], [ 49.58 ], [ 59.723 ], [ 50.43 ], [ 80.65300000000002 ], [ 44.74100000000001 ], [ 50.651 ], [ 78.553 ], [ 72.961 ], [ 72.889 ], [ 65.152 ], [ 46.462 ], [ 55.322 ], [ 78.782 ], [ 48.328 ], [ 75.748 ], [ 78.273 ], [ 76.486 ], [ 78.332 ], [ 54.791 ], [ 72.235 ], [ 74.994 ], [ 71.33800000000002 ], [ 71.878 ], [ 51.57899999999999 ], [ 58.03999999999999 ], [ 52.947 ], [ 79.313 ], [ 80.65699999999998 ], [ 56.73500000000001 ], [ 59.448 ], [ 79.406 ], [ 60.02199999999999 ], [ 79.483 ], [ 70.259 ], [ 56.007 ], [ 46.38800000000001 ], [ 60.916 ], [ 70.19800000000001 ], [ 82.208 ], [ 73.33800000000002 ], [ 81.757 ], [ 64.69800000000001 ], [ 70.65 ], [ 70.964 ], [ 59.545 ], [ 78.885 ], [ 80.745 ], [ 80.546 ], [ 72.567 ], [ 82.603 ], [ 72.535 ], [ 54.11 ], [ 67.297 ], [ 78.623 ], [ 77.58800000000002 ], [ 71.993 ], [ 42.592 ], [ 45.678 ], [ 73.952 ], [ 59.443000000000005 ], [ 48.303 ], [ 74.241 ], [ 54.467 ], [ 64.164 ], [ 72.801 ], [ 76.195 ], [ 66.803 ], [ 74.543 ], [ 71.164 ], [ 42.082 ], [ 62.06900000000001 ], [ 52.90600000000001 ], [ 63.785 ], [ 79.762 ], [ 80.204 ], [ 72.899 ], [ 56.867 ], [ 46.859 ], [ 80.196 ], [ 75.64 ], [ 65.483 ], [ 75.53699999999998 ], [ 71.752 ], [ 71.421 ], [ 71.688 ], [ 75.563 ], [ 78.098 ], [ 78.74600000000002 ], [ 76.442 ], [ 72.476 ], [ 46.242 ], [ 65.528 ], [ 72.777 ], [ 63.062 ], [ 74.002 ], [ 42.56800000000001 ], [ 79.972 ], [ 74.663 ], [ 77.926 ], [ 48.159 ], [ 49.339 ], [ 80.941 ], [ 72.396 ], [ 58.55599999999999 ], [ 39.613 ], [ 80.884 ], [ 81.70100000000002 ], [ 74.143 ], [ 78.4 ], [ 52.517 ], [ 70.616 ], [ 58.42 ], [ 69.819 ], [ 73.923 ], [ 71.777 ], [ 51.542 ], [ 79.425 ], [ 78.242 ], [ 76.384 ], [ 73.747 ], [ 74.249 ], [ 73.422 ], [ 62.698 ], [ 42.38399999999999 ], [ 43.487 ], [ 54.56441057558197 ], [ 75.35668222743027 ], [ 69.44386304205017 ], [ 77.89057081069897 ], [ 81.06215400970112 ], [ 68.91909251904043 ] ], "domain": { "x": [ 0, 1 ], "y": [ 0, 1 ] }, "hovertemplate": "labels=%{label}
pop=%{value}
parent=%{parent}
id=%{id}
lifeExp=%{color}", "ids": [ "World/Asia/Afghanistan", "World/Europe/Albania", "World/Africa/Algeria", "World/Africa/Angola", "World/Americas/Argentina", "World/Oceania/Australia", "World/Europe/Austria", "World/Asia/Bahrain", "World/Asia/Bangladesh", "World/Europe/Belgium", "World/Africa/Benin", "World/Americas/Bolivia", "World/Europe/Bosnia and Herzegovina", "World/Africa/Botswana", "World/Americas/Brazil", "World/Europe/Bulgaria", "World/Africa/Burkina Faso", "World/Africa/Burundi", "World/Asia/Cambodia", "World/Africa/Cameroon", "World/Americas/Canada", "World/Africa/Central African Republic", "World/Africa/Chad", "World/Americas/Chile", "World/Asia/China", "World/Americas/Colombia", "World/Africa/Comoros", "World/Africa/Congo, Dem. Rep.", "World/Africa/Congo, Rep.", "World/Americas/Costa Rica", "World/Africa/Cote d'Ivoire", "World/Europe/Croatia", "World/Americas/Cuba", "World/Europe/Czech Republic", "World/Europe/Denmark", "World/Africa/Djibouti", "World/Americas/Dominican Republic", "World/Americas/Ecuador", "World/Africa/Egypt", "World/Americas/El Salvador", "World/Africa/Equatorial Guinea", "World/Africa/Eritrea", "World/Africa/Ethiopia", "World/Europe/Finland", "World/Europe/France", "World/Africa/Gabon", "World/Africa/Gambia", "World/Europe/Germany", "World/Africa/Ghana", "World/Europe/Greece", "World/Americas/Guatemala", "World/Africa/Guinea", "World/Africa/Guinea-Bissau", "World/Americas/Haiti", "World/Americas/Honduras", "World/Asia/Hong Kong, China", "World/Europe/Hungary", "World/Europe/Iceland", "World/Asia/India", "World/Asia/Indonesia", "World/Asia/Iran", "World/Asia/Iraq", "World/Europe/Ireland", "World/Asia/Israel", "World/Europe/Italy", "World/Americas/Jamaica", "World/Asia/Japan", "World/Asia/Jordan", "World/Africa/Kenya", "World/Asia/Korea, Dem. Rep.", "World/Asia/Korea, Rep.", "World/Asia/Kuwait", "World/Asia/Lebanon", "World/Africa/Lesotho", "World/Africa/Liberia", "World/Africa/Libya", "World/Africa/Madagascar", "World/Africa/Malawi", "World/Asia/Malaysia", "World/Africa/Mali", "World/Africa/Mauritania", "World/Africa/Mauritius", "World/Americas/Mexico", "World/Asia/Mongolia", "World/Europe/Montenegro", "World/Africa/Morocco", "World/Africa/Mozambique", "World/Asia/Myanmar", "World/Africa/Namibia", "World/Asia/Nepal", "World/Europe/Netherlands", "World/Oceania/New Zealand", "World/Americas/Nicaragua", "World/Africa/Niger", "World/Africa/Nigeria", "World/Europe/Norway", "World/Asia/Oman", "World/Asia/Pakistan", "World/Americas/Panama", "World/Americas/Paraguay", "World/Americas/Peru", "World/Asia/Philippines", "World/Europe/Poland", "World/Europe/Portugal", "World/Americas/Puerto Rico", "World/Africa/Reunion", "World/Europe/Romania", "World/Africa/Rwanda", "World/Africa/Sao Tome and Principe", "World/Asia/Saudi Arabia", "World/Africa/Senegal", "World/Europe/Serbia", "World/Africa/Sierra Leone", "World/Asia/Singapore", "World/Europe/Slovak Republic", "World/Europe/Slovenia", "World/Africa/Somalia", "World/Africa/South Africa", "World/Europe/Spain", "World/Asia/Sri Lanka", "World/Africa/Sudan", "World/Africa/Swaziland", "World/Europe/Sweden", "World/Europe/Switzerland", "World/Asia/Syria", "World/Asia/Taiwan", "World/Africa/Tanzania", "World/Asia/Thailand", "World/Africa/Togo", "World/Americas/Trinidad and Tobago", "World/Africa/Tunisia", "World/Europe/Turkey", "World/Africa/Uganda", "World/Europe/United Kingdom", "World/Americas/United States", "World/Americas/Uruguay", "World/Americas/Venezuela", "World/Asia/Vietnam", "World/Asia/West Bank and Gaza", "World/Asia/Yemen, Rep.", "World/Africa/Zambia", "World/Africa/Zimbabwe", "World/Africa", "World/Americas", "World/Asia", "World/Europe", "World/Oceania", "World" ], "labels": [ "Afghanistan", "Albania", "Algeria", "Angola", "Argentina", "Australia", "Austria", "Bahrain", "Bangladesh", "Belgium", "Benin", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo, Dem. Rep.", "Congo, Rep.", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Czech Republic", "Denmark", "Djibouti", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Ethiopia", "Finland", "France", "Gabon", "Gambia", "Germany", "Ghana", "Greece", "Guatemala", "Guinea", "Guinea-Bissau", "Haiti", "Honduras", "Hong Kong, China", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kenya", "Korea, Dem. Rep.", "Korea, Rep.", "Kuwait", "Lebanon", "Lesotho", "Liberia", "Libya", "Madagascar", "Malawi", "Malaysia", "Mali", "Mauritania", "Mauritius", "Mexico", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Panama", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Reunion", "Romania", "Rwanda", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Sierra Leone", "Singapore", "Slovak Republic", "Slovenia", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tanzania", "Thailand", "Togo", "Trinidad and Tobago", "Tunisia", "Turkey", "Uganda", "United Kingdom", "United States", "Uruguay", "Venezuela", "Vietnam", "West Bank and Gaza", "Yemen, Rep.", "Zambia", "Zimbabwe", "Africa", "Americas", "Asia", "Europe", "Oceania", "World" ], "marker": { "coloraxis": "coloraxis", "colors": [ 43.828, 76.423, 72.301, 42.731, 75.32, 81.235, 79.829, 75.635, 64.062, 79.441, 56.728, 65.554, 74.852, 50.728, 72.39, 73.005, 52.295, 49.58, 59.723, 50.43, 80.65300000000002, 44.74100000000001, 50.651, 78.553, 72.961, 72.889, 65.152, 46.462, 55.322, 78.782, 48.328, 75.748, 78.273, 76.486, 78.332, 54.791, 72.235, 74.994, 71.33800000000002, 71.878, 51.57899999999999, 58.03999999999999, 52.947, 79.313, 80.65699999999998, 56.73500000000001, 59.448, 79.406, 60.02199999999999, 79.483, 70.259, 56.007, 46.38800000000001, 60.916, 70.19800000000001, 82.208, 73.33800000000002, 81.757, 64.69800000000001, 70.65, 70.964, 59.545, 78.885, 80.745, 80.546, 72.567, 82.603, 72.535, 54.11, 67.297, 78.623, 77.58800000000002, 71.993, 42.592, 45.678, 73.952, 59.443000000000005, 48.303, 74.241, 54.467, 64.164, 72.801, 76.195, 66.803, 74.543, 71.164, 42.082, 62.06900000000001, 52.90600000000001, 63.785, 79.762, 80.204, 72.899, 56.867, 46.859, 80.196, 75.64, 65.483, 75.53699999999998, 71.752, 71.421, 71.688, 75.563, 78.098, 78.74600000000002, 76.442, 72.476, 46.242, 65.528, 72.777, 63.062, 74.002, 42.56800000000001, 79.972, 74.663, 77.926, 48.159, 49.339, 80.941, 72.396, 58.55599999999999, 39.613, 80.884, 81.70100000000002, 74.143, 78.4, 52.517, 70.616, 58.42, 69.819, 73.923, 71.777, 51.542, 79.425, 78.242, 76.384, 73.747, 74.249, 73.422, 62.698, 42.38399999999999, 43.487, 54.56441057558197, 75.35668222743027, 69.44386304205017, 77.89057081069897, 81.06215400970112, 68.91909251904043 ] }, "name": "", "parents": [ "World/Asia", "World/Europe", "World/Africa", "World/Africa", "World/Americas", "World/Oceania", "World/Europe", "World/Asia", "World/Asia", "World/Europe", "World/Africa", "World/Americas", "World/Europe", "World/Africa", "World/Americas", "World/Europe", "World/Africa", "World/Africa", "World/Asia", "World/Africa", "World/Americas", "World/Africa", "World/Africa", "World/Americas", "World/Asia", "World/Americas", "World/Africa", "World/Africa", "World/Africa", "World/Americas", "World/Africa", "World/Europe", "World/Americas", "World/Europe", "World/Europe", "World/Africa", "World/Americas", "World/Americas", "World/Africa", "World/Americas", "World/Africa", "World/Africa", "World/Africa", "World/Europe", "World/Europe", "World/Africa", "World/Africa", "World/Europe", "World/Africa", "World/Europe", "World/Americas", "World/Africa", "World/Africa", "World/Americas", "World/Americas", "World/Asia", "World/Europe", "World/Europe", "World/Asia", "World/Asia", "World/Asia", "World/Asia", "World/Europe", "World/Asia", "World/Europe", "World/Americas", "World/Asia", "World/Asia", "World/Africa", "World/Asia", "World/Asia", "World/Asia", "World/Asia", "World/Africa", "World/Africa", "World/Africa", "World/Africa", "World/Africa", "World/Asia", "World/Africa", "World/Africa", "World/Africa", "World/Americas", "World/Asia", "World/Europe", "World/Africa", "World/Africa", "World/Asia", "World/Africa", "World/Asia", "World/Europe", "World/Oceania", "World/Americas", "World/Africa", "World/Africa", "World/Europe", "World/Asia", "World/Asia", "World/Americas", "World/Americas", "World/Americas", "World/Asia", "World/Europe", "World/Europe", "World/Americas", "World/Africa", "World/Europe", "World/Africa", "World/Africa", "World/Asia", "World/Africa", "World/Europe", "World/Africa", "World/Asia", "World/Europe", "World/Europe", "World/Africa", "World/Africa", "World/Europe", "World/Asia", "World/Africa", "World/Africa", "World/Europe", "World/Europe", "World/Asia", "World/Asia", "World/Africa", "World/Asia", "World/Africa", "World/Americas", "World/Africa", "World/Europe", "World/Africa", "World/Europe", "World/Americas", "World/Americas", "World/Americas", "World/Asia", "World/Asia", "World/Asia", "World/Africa", "World/Africa", "World", "World", "World", "World", "World", "" ], "type": "icicle", "values": [ 31889923, 3600523, 33333216, 12420476, 40301927, 20434176, 8199783, 708573, 150448339, 10392226, 8078314, 9119152, 4552198, 1639131, 190010647, 7322858, 14326203, 8390505, 14131858, 17696293, 33390141, 4369038, 10238807, 16284741, 1318683096, 44227550, 710960, 64606759, 3800610, 4133884, 18013409, 4493312, 11416987, 10228744, 5468120, 496374, 9319622, 13755680, 80264543, 6939688, 551201, 4906585, 76511887, 5238460, 61083916, 1454867, 1688359, 82400996, 22873338, 10706290, 12572928, 9947814, 1472041, 8502814, 7483763, 6980412, 9956108, 301931, 1110396331, 223547000, 69453570, 27499638, 4109086, 6426679, 58147733, 2780132, 127467972, 6053193, 35610177, 23301725, 49044790, 2505559, 3921278, 2012649, 3193942, 6036914, 19167654, 13327079, 24821286, 12031795, 3270065, 1250882, 108700891, 2874127, 684736, 33757175, 19951656, 47761980, 2055080, 28901790, 16570613, 4115771, 5675356, 12894865, 135031164, 4627926, 3204897, 169270617, 3242173, 6667147, 28674757, 91077287, 38518241, 10642836, 3942491, 798094, 22276056, 8860588, 199579, 27601038, 12267493, 10150265, 6144562, 4553009, 5447502, 2009245, 9118773, 43997828, 40448191, 20378239, 42292929, 1133066, 9031088, 7554661, 19314747, 23174294, 38139640, 65068149, 5701579, 1056608, 10276158, 71158647, 29170398, 60776238, 301139947, 3447496, 26084662, 85262356, 4018332, 22211743, 11746035, 12311143, 929539692, 898871184, 3811953827, 586098529, 24549947, 6251013179 ] } ], "layout": { "coloraxis": { "colorbar": { "title": { "text": "lifeExp" } }, "colorscale": [ [ 0, "rgb(103,0,31)" ], [ 0.1, "rgb(178,24,43)" ], [ 0.2, "rgb(214,96,77)" ], [ 0.3, "rgb(244,165,130)" ], [ 0.4, "rgb(253,219,199)" ], [ 0.5, "rgb(247,247,247)" ], [ 0.6, "rgb(209,229,240)" ], [ 0.7, "rgb(146,197,222)" ], [ 0.8, "rgb(67,147,195)" ], [ 0.9, "rgb(33,102,172)" ], [ 1, "rgb(5,48,97)" ] ] }, "height": 700, "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": "Life Expectancy accross Regions in 2007" }, "width": 700 } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = px.icicle(df2, path=[px.Constant(\"World\"), 'continent', 'country'], \n", " values='pop',\n", " color='lifeExp',\n", " color_continuous_scale='RdBu',\n", " height=700, width=700,\n", " title='Life Expectancy accross Regions in 2007')\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3. Set the midpoint of the color bar to the average Life Expectancy weighted by the population size of each country" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "branchvalues": "total", "customdata": [ [ "AFG", 43.828 ], [ "ALB", 76.423 ], [ "DZA", 72.301 ], [ "AGO", 42.731 ], [ "ARG", 75.32 ], [ "AUS", 81.235 ], [ "AUT", 79.829 ], [ "BHR", 75.635 ], [ "BGD", 64.062 ], [ "BEL", 79.441 ], [ "BEN", 56.728 ], [ "BOL", 65.554 ], [ "BIH", 74.852 ], [ "BWA", 50.728 ], [ "BRA", 72.39 ], [ "BGR", 73.005 ], [ "BFA", 52.295 ], [ "BDI", 49.58 ], [ "KHM", 59.723 ], [ "CMR", 50.43 ], [ "CAN", 80.65300000000002 ], [ "CAF", 44.74100000000001 ], [ "TCD", 50.651 ], [ "CHL", 78.553 ], [ "CHN", 72.961 ], [ "COL", 72.889 ], [ "COM", 65.152 ], [ "COD", 46.462 ], [ "COG", 55.322 ], [ "CRI", 78.782 ], [ "CIV", 48.328 ], [ "HRV", 75.748 ], [ "CUB", 78.273 ], [ "CZE", 76.486 ], [ "DNK", 78.332 ], [ "DJI", 54.791 ], [ "DOM", 72.235 ], [ "ECU", 74.994 ], [ "EGY", 71.33800000000002 ], [ "SLV", 71.878 ], [ "GNQ", 51.57899999999999 ], [ "ERI", 58.03999999999999 ], [ "ETH", 52.947 ], [ "FIN", 79.313 ], [ "FRA", 80.65699999999998 ], [ "GAB", 56.73500000000001 ], [ "GMB", 59.448 ], [ "DEU", 79.406 ], [ "GHA", 60.02199999999999 ], [ "GRC", 79.483 ], [ "GTM", 70.259 ], [ "GIN", 56.007 ], [ "GNB", 46.38800000000001 ], [ "HTI", 60.916 ], [ "HND", 70.19800000000001 ], [ "HKG", 82.208 ], [ "HUN", 73.33800000000002 ], [ "ISL", 81.757 ], [ "IND", 64.69800000000001 ], [ "IDN", 70.65 ], [ "IRN", 70.964 ], [ "IRQ", 59.545 ], [ "IRL", 78.885 ], [ "ISR", 80.745 ], [ "ITA", 80.546 ], [ "JAM", 72.567 ], [ "JPN", 82.603 ], [ "JOR", 72.535 ], [ "KEN", 54.11 ], [ "KOR", 67.297 ], [ "KOR", 78.623 ], [ "KWT", 77.58800000000002 ], [ "LBN", 71.993 ], [ "LSO", 42.592 ], [ "LBR", 45.678 ], [ "LBY", 73.952 ], [ "MDG", 59.443000000000005 ], [ "MWI", 48.303 ], [ "MYS", 74.241 ], [ "MLI", 54.467 ], [ "MRT", 64.164 ], [ "MUS", 72.801 ], [ "MEX", 76.195 ], [ "MNG", 66.803 ], [ "MNE", 74.543 ], [ "MAR", 71.164 ], [ "MOZ", 42.082 ], [ "MMR", 62.06900000000001 ], [ "NAM", 52.90600000000001 ], [ "NPL", 63.785 ], [ "NLD", 79.762 ], [ "NZL", 80.204 ], [ "NIC", 72.899 ], [ "NER", 56.867 ], [ "NGA", 46.859 ], [ "NOR", 80.196 ], [ "OMN", 75.64 ], [ "PAK", 65.483 ], [ "PAN", 75.53699999999998 ], [ "PRY", 71.752 ], [ "PER", 71.421 ], [ "PHL", 71.688 ], [ "POL", 75.563 ], [ "PRT", 78.098 ], [ "PRI", 78.74600000000002 ], [ "REU", 76.442 ], [ "ROU", 72.476 ], [ "RWA", 46.242 ], [ "STP", 65.528 ], [ "SAU", 72.777 ], [ "SEN", 63.062 ], [ "SRB", 74.002 ], [ "SLE", 42.56800000000001 ], [ "SGP", 79.972 ], [ "SVK", 74.663 ], [ "SVN", 77.926 ], [ "SOM", 48.159 ], [ "ZAF", 49.339 ], [ "ESP", 80.941 ], [ "LKA", 72.396 ], [ "SDN", 58.55599999999999 ], [ "SWZ", 39.613 ], [ "SWE", 80.884 ], [ "CHE", 81.70100000000002 ], [ "SYR", 74.143 ], [ "TWN", 78.4 ], [ "TZA", 52.517 ], [ "THA", 70.616 ], [ "TGO", 58.42 ], [ "TTO", 69.819 ], [ "TUN", 73.923 ], [ "TUR", 71.777 ], [ "UGA", 51.542 ], [ "GBR", 79.425 ], [ "USA", 78.242 ], [ "URY", 76.384 ], [ "VEN", 73.747 ], [ "VNM", 74.249 ], [ "PSE", 73.422 ], [ "YEM", 62.698 ], [ "ZMB", 42.38399999999999 ], [ "ZWE", 43.487 ], [ "(?)", 54.56441057558197 ], [ "(?)", 75.35668222743027 ], [ "(?)", 69.44386304205017 ], [ "(?)", 77.89057081069897 ], [ "(?)", 81.06215400970112 ], [ "(?)", 68.91909251904043 ] ], "domain": { "x": [ 0, 1 ], "y": [ 0, 1 ] }, "hovertemplate": "labels=%{label}
pop=%{value}
parent=%{parent}
id=%{id}
iso_alpha=%{customdata[0]}
lifeExp=%{color}", "ids": [ "world/Asia/Afghanistan", "world/Europe/Albania", "world/Africa/Algeria", "world/Africa/Angola", "world/Americas/Argentina", "world/Oceania/Australia", "world/Europe/Austria", "world/Asia/Bahrain", "world/Asia/Bangladesh", "world/Europe/Belgium", "world/Africa/Benin", "world/Americas/Bolivia", "world/Europe/Bosnia and Herzegovina", "world/Africa/Botswana", "world/Americas/Brazil", "world/Europe/Bulgaria", "world/Africa/Burkina Faso", "world/Africa/Burundi", "world/Asia/Cambodia", "world/Africa/Cameroon", "world/Americas/Canada", "world/Africa/Central African Republic", "world/Africa/Chad", "world/Americas/Chile", "world/Asia/China", "world/Americas/Colombia", "world/Africa/Comoros", "world/Africa/Congo, Dem. Rep.", "world/Africa/Congo, Rep.", "world/Americas/Costa Rica", "world/Africa/Cote d'Ivoire", "world/Europe/Croatia", "world/Americas/Cuba", "world/Europe/Czech Republic", "world/Europe/Denmark", "world/Africa/Djibouti", "world/Americas/Dominican Republic", "world/Americas/Ecuador", "world/Africa/Egypt", "world/Americas/El Salvador", "world/Africa/Equatorial Guinea", "world/Africa/Eritrea", "world/Africa/Ethiopia", "world/Europe/Finland", "world/Europe/France", "world/Africa/Gabon", "world/Africa/Gambia", "world/Europe/Germany", "world/Africa/Ghana", "world/Europe/Greece", "world/Americas/Guatemala", "world/Africa/Guinea", "world/Africa/Guinea-Bissau", "world/Americas/Haiti", "world/Americas/Honduras", "world/Asia/Hong Kong, China", "world/Europe/Hungary", "world/Europe/Iceland", "world/Asia/India", "world/Asia/Indonesia", "world/Asia/Iran", "world/Asia/Iraq", "world/Europe/Ireland", "world/Asia/Israel", "world/Europe/Italy", "world/Americas/Jamaica", "world/Asia/Japan", "world/Asia/Jordan", "world/Africa/Kenya", "world/Asia/Korea, Dem. Rep.", "world/Asia/Korea, Rep.", "world/Asia/Kuwait", "world/Asia/Lebanon", "world/Africa/Lesotho", "world/Africa/Liberia", "world/Africa/Libya", "world/Africa/Madagascar", "world/Africa/Malawi", "world/Asia/Malaysia", "world/Africa/Mali", "world/Africa/Mauritania", "world/Africa/Mauritius", "world/Americas/Mexico", "world/Asia/Mongolia", "world/Europe/Montenegro", "world/Africa/Morocco", "world/Africa/Mozambique", "world/Asia/Myanmar", "world/Africa/Namibia", "world/Asia/Nepal", "world/Europe/Netherlands", "world/Oceania/New Zealand", "world/Americas/Nicaragua", "world/Africa/Niger", "world/Africa/Nigeria", "world/Europe/Norway", "world/Asia/Oman", "world/Asia/Pakistan", "world/Americas/Panama", "world/Americas/Paraguay", "world/Americas/Peru", "world/Asia/Philippines", "world/Europe/Poland", "world/Europe/Portugal", "world/Americas/Puerto Rico", "world/Africa/Reunion", "world/Europe/Romania", "world/Africa/Rwanda", "world/Africa/Sao Tome and Principe", "world/Asia/Saudi Arabia", "world/Africa/Senegal", "world/Europe/Serbia", "world/Africa/Sierra Leone", "world/Asia/Singapore", "world/Europe/Slovak Republic", "world/Europe/Slovenia", "world/Africa/Somalia", "world/Africa/South Africa", "world/Europe/Spain", "world/Asia/Sri Lanka", "world/Africa/Sudan", "world/Africa/Swaziland", "world/Europe/Sweden", "world/Europe/Switzerland", "world/Asia/Syria", "world/Asia/Taiwan", "world/Africa/Tanzania", "world/Asia/Thailand", "world/Africa/Togo", "world/Americas/Trinidad and Tobago", "world/Africa/Tunisia", "world/Europe/Turkey", "world/Africa/Uganda", "world/Europe/United Kingdom", "world/Americas/United States", "world/Americas/Uruguay", "world/Americas/Venezuela", "world/Asia/Vietnam", "world/Asia/West Bank and Gaza", "world/Asia/Yemen, Rep.", "world/Africa/Zambia", "world/Africa/Zimbabwe", "world/Africa", "world/Americas", "world/Asia", "world/Europe", "world/Oceania", "world" ], "labels": [ "Afghanistan", "Albania", "Algeria", "Angola", "Argentina", "Australia", "Austria", "Bahrain", "Bangladesh", "Belgium", "Benin", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo, Dem. Rep.", "Congo, Rep.", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Czech Republic", "Denmark", "Djibouti", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Ethiopia", "Finland", "France", "Gabon", "Gambia", "Germany", "Ghana", "Greece", "Guatemala", "Guinea", "Guinea-Bissau", "Haiti", "Honduras", "Hong Kong, China", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kenya", "Korea, Dem. Rep.", "Korea, Rep.", "Kuwait", "Lebanon", "Lesotho", "Liberia", "Libya", "Madagascar", "Malawi", "Malaysia", "Mali", "Mauritania", "Mauritius", "Mexico", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Panama", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Reunion", "Romania", "Rwanda", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Sierra Leone", "Singapore", "Slovak Republic", "Slovenia", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tanzania", "Thailand", "Togo", "Trinidad and Tobago", "Tunisia", "Turkey", "Uganda", "United Kingdom", "United States", "Uruguay", "Venezuela", "Vietnam", "West Bank and Gaza", "Yemen, Rep.", "Zambia", "Zimbabwe", "Africa", "Americas", "Asia", "Europe", "Oceania", "world" ], "marker": { "coloraxis": "coloraxis", "colors": [ 43.828, 76.423, 72.301, 42.731, 75.32, 81.235, 79.829, 75.635, 64.062, 79.441, 56.728, 65.554, 74.852, 50.728, 72.39, 73.005, 52.295, 49.58, 59.723, 50.43, 80.65300000000002, 44.74100000000001, 50.651, 78.553, 72.961, 72.889, 65.152, 46.462, 55.322, 78.782, 48.328, 75.748, 78.273, 76.486, 78.332, 54.791, 72.235, 74.994, 71.33800000000002, 71.878, 51.57899999999999, 58.03999999999999, 52.947, 79.313, 80.65699999999998, 56.73500000000001, 59.448, 79.406, 60.02199999999999, 79.483, 70.259, 56.007, 46.38800000000001, 60.916, 70.19800000000001, 82.208, 73.33800000000002, 81.757, 64.69800000000001, 70.65, 70.964, 59.545, 78.885, 80.745, 80.546, 72.567, 82.603, 72.535, 54.11, 67.297, 78.623, 77.58800000000002, 71.993, 42.592, 45.678, 73.952, 59.443000000000005, 48.303, 74.241, 54.467, 64.164, 72.801, 76.195, 66.803, 74.543, 71.164, 42.082, 62.06900000000001, 52.90600000000001, 63.785, 79.762, 80.204, 72.899, 56.867, 46.859, 80.196, 75.64, 65.483, 75.53699999999998, 71.752, 71.421, 71.688, 75.563, 78.098, 78.74600000000002, 76.442, 72.476, 46.242, 65.528, 72.777, 63.062, 74.002, 42.56800000000001, 79.972, 74.663, 77.926, 48.159, 49.339, 80.941, 72.396, 58.55599999999999, 39.613, 80.884, 81.70100000000002, 74.143, 78.4, 52.517, 70.616, 58.42, 69.819, 73.923, 71.777, 51.542, 79.425, 78.242, 76.384, 73.747, 74.249, 73.422, 62.698, 42.38399999999999, 43.487, 54.56441057558197, 75.35668222743027, 69.44386304205017, 77.89057081069897, 81.06215400970112, 68.91909251904043 ] }, "name": "", "parents": [ "world/Asia", "world/Europe", "world/Africa", "world/Africa", "world/Americas", "world/Oceania", "world/Europe", "world/Asia", "world/Asia", "world/Europe", "world/Africa", "world/Americas", "world/Europe", "world/Africa", "world/Americas", "world/Europe", "world/Africa", "world/Africa", "world/Asia", "world/Africa", "world/Americas", "world/Africa", "world/Africa", "world/Americas", "world/Asia", "world/Americas", "world/Africa", "world/Africa", "world/Africa", "world/Americas", "world/Africa", "world/Europe", "world/Americas", "world/Europe", "world/Europe", "world/Africa", "world/Americas", "world/Americas", "world/Africa", "world/Americas", "world/Africa", "world/Africa", "world/Africa", "world/Europe", "world/Europe", "world/Africa", "world/Africa", "world/Europe", "world/Africa", "world/Europe", "world/Americas", "world/Africa", "world/Africa", "world/Americas", "world/Americas", "world/Asia", "world/Europe", "world/Europe", "world/Asia", "world/Asia", "world/Asia", "world/Asia", "world/Europe", "world/Asia", "world/Europe", "world/Americas", "world/Asia", "world/Asia", "world/Africa", "world/Asia", "world/Asia", "world/Asia", "world/Asia", "world/Africa", "world/Africa", "world/Africa", "world/Africa", "world/Africa", "world/Asia", "world/Africa", "world/Africa", "world/Africa", "world/Americas", "world/Asia", "world/Europe", "world/Africa", "world/Africa", "world/Asia", "world/Africa", "world/Asia", "world/Europe", "world/Oceania", "world/Americas", "world/Africa", "world/Africa", "world/Europe", "world/Asia", "world/Asia", "world/Americas", "world/Americas", "world/Americas", "world/Asia", "world/Europe", "world/Europe", "world/Americas", "world/Africa", "world/Europe", "world/Africa", "world/Africa", "world/Asia", "world/Africa", "world/Europe", "world/Africa", "world/Asia", "world/Europe", "world/Europe", "world/Africa", "world/Africa", "world/Europe", "world/Asia", "world/Africa", "world/Africa", "world/Europe", "world/Europe", "world/Asia", "world/Asia", "world/Africa", "world/Asia", "world/Africa", "world/Americas", "world/Africa", "world/Europe", "world/Africa", "world/Europe", "world/Americas", "world/Americas", "world/Americas", "world/Asia", "world/Asia", "world/Asia", "world/Africa", "world/Africa", "world", "world", "world", "world", "world", "" ], "type": "icicle", "values": [ 31889923, 3600523, 33333216, 12420476, 40301927, 20434176, 8199783, 708573, 150448339, 10392226, 8078314, 9119152, 4552198, 1639131, 190010647, 7322858, 14326203, 8390505, 14131858, 17696293, 33390141, 4369038, 10238807, 16284741, 1318683096, 44227550, 710960, 64606759, 3800610, 4133884, 18013409, 4493312, 11416987, 10228744, 5468120, 496374, 9319622, 13755680, 80264543, 6939688, 551201, 4906585, 76511887, 5238460, 61083916, 1454867, 1688359, 82400996, 22873338, 10706290, 12572928, 9947814, 1472041, 8502814, 7483763, 6980412, 9956108, 301931, 1110396331, 223547000, 69453570, 27499638, 4109086, 6426679, 58147733, 2780132, 127467972, 6053193, 35610177, 23301725, 49044790, 2505559, 3921278, 2012649, 3193942, 6036914, 19167654, 13327079, 24821286, 12031795, 3270065, 1250882, 108700891, 2874127, 684736, 33757175, 19951656, 47761980, 2055080, 28901790, 16570613, 4115771, 5675356, 12894865, 135031164, 4627926, 3204897, 169270617, 3242173, 6667147, 28674757, 91077287, 38518241, 10642836, 3942491, 798094, 22276056, 8860588, 199579, 27601038, 12267493, 10150265, 6144562, 4553009, 5447502, 2009245, 9118773, 43997828, 40448191, 20378239, 42292929, 1133066, 9031088, 7554661, 19314747, 23174294, 38139640, 65068149, 5701579, 1056608, 10276158, 71158647, 29170398, 60776238, 301139947, 3447496, 26084662, 85262356, 4018332, 22211743, 11746035, 12311143, 929539692, 898871184, 3811953827, 586098529, 24549947, 6251013179 ] } ], "layout": { "coloraxis": { "cmid": 68.91909251904043, "colorbar": { "title": { "text": "lifeExp" } }, "colorscale": [ [ 0, "rgb(103,0,31)" ], [ 0.1, "rgb(178,24,43)" ], [ 0.2, "rgb(214,96,77)" ], [ 0.3, "rgb(244,165,130)" ], [ 0.4, "rgb(253,219,199)" ], [ 0.5, "rgb(247,247,247)" ], [ 0.6, "rgb(209,229,240)" ], [ 0.7, "rgb(146,197,222)" ], [ 0.8, "rgb(67,147,195)" ], [ 0.9, "rgb(33,102,172)" ], [ 1, "rgb(5,48,97)" ] ] }, "height": 700, "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": "Life Expectancy accross Regions in 2007" }, "width": 700 } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "average_life_exp_pop = np.average(df2['lifeExp'], weights=df2['pop'])\n", "\n", "fig = px.icicle(df2, path=[px.Constant(\"world\"), 'continent', 'country'], values='pop',\n", " color='lifeExp', hover_data=['iso_alpha'],\n", " color_continuous_scale='RdBu',\n", " color_continuous_midpoint=average_life_exp_pop,\n", " height=700, width=700,\n", " title='Life Expectancy accross Regions in 2007'\n", " )\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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 }