{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "*Na naucse.python.cz bohužel nefunguje zobrazování interaktivních plotly grafů. Pro zobrazení včetně grafů můžeš použít nbviewer: https://nbviewer.jupyter.org/github/PyDataCZ/pydataladies-dashboard/blob/main/notebooks/dashboardy-1.ipynb nebo si notebook pustit lokálně. Všechny soubory pohromadě najdeš v repozitáři https://github.com/PyDataCZ/pydataladies-dashboard.*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "# Interaktivní vizualizace a aplikace\n", "\n", "Při práci s daty je mnoho příležitostí, kdy se hodí interaktivita. Při vizualici se hodí zvětšování / zmenšování měřítka, výběr podoblasti, ukázání vykreslených hodnot apod. Nebo při datové analýze obecně se může hodit interaktivně v notebooku měnit nějaký parametr (třeba hyperparametr pro strojové učení). Anebo chceme dát výsledky naší skvělé analýzy k dispozici \"netechnickým\" kolegům nebo kamarádům, kteří (zatím) nedokáží Jupyter notebook spustit.\n", "\n", "Tady si ukážeme, jak si s takovými úkoly poradit pomocí dvou nástrojů: [plotly](https://plotly.com/python/), resp. především [plotly express](https://plotly.com/python/plotly-express/), a [streamlit](https://www.streamlit.io/).\n", "\n", "Existují i další nástroje, které poskytují podobné možnosti. Podrobný přehled najdete na https://pyviz.org/tools.html. Na interaktivní vizualizace jsou to především [holoviews](http://github.com/pyviz/holoviews) nebo [altair](http://github.com/altair-viz/altair). Na \"dashboarding\" pak [dash](http://github.com/plotly/dash), [panel](https://panel.holoviz.org/), [voila](http://github.com/QuantStack/voila), nebo [vizro](https://github.com/mckinsey/vizro). Za zmínku stojí také projekty [NiceGUI](https://github.com/zauberzeug/nicegui) nebo [FastHTML](https://fastht.ml), kde lze vytvářet i složitější webové aplikace.\n", "\n", "Velmi atraktivními novinkami jsou [JupyterLite](https://github.com/jupyterlite/jupyterlite), [voici](https://github.com/voila-dashboards/voici) a [PyScript](https://pyscript.net). Oba projekty těží z možnosti spustit Python kód přímo ve webovém prohlížeči, konkrétně v jeho virtuálním stroji, díky technologie Web Assembly. \n", "* JupyteLite umožňuje spustit Jupyter notebooky v prohlížeči, bez nutnosti instalace Pythonu, a to včetně knihoven na zpracováni dat jako jsou NumPy, Pandas apod. Více se můžeš dozvědět také z přednášky na pražském PyData meetup: [Jeremy Tuloup - JupyterLite: Jupyter ❤️ WebAssembly ❤️ Python (slides, video)](https://pydata.cz/#jeremy-tuloup---jupyterlite-jupyter-%EF%B8%8F-webassembly-%EF%B8%8F-python-slides-video).\n", "* Voici využívá JupyterLite a umožňuje spustit Jupyter notebooky jako interaktivní webové aplikace bez nutnosti instalace Pythonu lokálně či na serveru.\n", "* PyScript umožňuje vložit Python kód přímo do HTML kódu a tímto způsobem vytvářet interaktivní webové aplikace přímo V Pythonu. PyScript tak vlastně \"nahrazuje\" JavaScript.\n", "\n", "Každý z těchto nástrojů má, jako obvykle, své výhody a nevýhody. Pravděpodobně nejrozšířenějším nástrojem je [Dash](http://github.com/plotly/dash) ze stejné dílny jako plotly, který poskytuje i enterprise řešení pro provoz aplikací. Dash je určitě dobrou volbou, jak se můžete dozvědět i na [přednášce z pražského PyData Meetupu](https://www.youtube.com/watch?v=dewrzMPPLDU). Panel (a také Voila) se od Dash liší tím, že je lze použít i v Jupyter notebooku a pak notebook použít přímo jako aplikaci. Největší přednost `voila` je jednoduchý způsob, jak udělat dashboard přímo z notebooku: viz [dokumentace](https://voila.readthedocs.io/en/stable/using.html).\n", "\n", "Dvě největší výhody Streamlitu jsou rychlost (jednoduchost) vývoje aplikace a atraktivní výchozí vzhled. Streamlit také (nedávno) přidal možnost vzájemné interakce mezi widgety pomocí callback funkcí. Pro Streamlit lze také poměrně snadno vytvářet nové komponenty, důkazem toho budiž [galerie komponent](https://streamlit.io/components).\n", "\n", "Pár článků či přednášek, které se tématu týkají:\n", "* [Dash, Voila, Panel, & Streamlit—Our Thoughts on the Big Four Dashboarding Tools](https://quansight.com/post/dash-voila-panel-streamlit-our-thoughts-on-the-big-four-dashboarding-tools)\n", "* [Pure Python Web Development](https://metaperl.github.io/pure-python-web-development/intro.html) - velký přehled knihoven pro webový vývoj v Pythonu.\n", "* [Streamlit - The fastest way to build and share data science apps](https://www.youtube.com/watch?v=sdgTYy3BJiM)\n", "* [How to Build a Reporting Dashboard using Dash and Plotly](https://towardsdatascience.com/how-to-build-a-complex-reporting-dashboard-using-dash-and-plotl-4f4257c18a7f)\n", "* [Turn any Notebook into a Deployable Dashboard | SciPy 2019 | James Bednar](https://www.youtube.com/watch?v=L91rd1D6XTA)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pro a proti\n", "\n", "Je potřeba ale říct, že všechny zmíněné přístupy mají své výrazné nevýhody a limity a nehodí se pro velké a složité aplikace. Možnosti interakcí v aplikaci jsou omezené a také mohou být pomalé. Robustní škálování pro mnoho uživatelů (velký provoz) je obecně složitější. Kdy tedy především použít, co si tady ukážeme?\n", "* Na malou aplikaci pro omezený počet uživatelů (dashboard pro kolegy).\n", "* Na rychlý vývoj prototypu.\n", "\n", "A co když chceme budovat velkou (webovou) aplikaci?\n", "* Zadáme vývojářskému týmu, aby v moderních JavaScript nástrojích typu React nebo Vue.js pro nás vytvořil krásný a rychlý \"front-end\", zatímco my vytvoříme v Pythonu \"back-end\", který s front-endem bude komunikovat např. pomocí JSON API. To uvidíme i v naší lekci o API.\n", "* Když takový tým nemáme, naučíme se programovat v JavaScriptu ... Ne, raději v TypeScriptu ... Zkusíme PyScript ...\n", "* ... nakonec najmeme front-end vývojářský tým pokud je to možné :-)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Instalace a import grafických knihoven\n", "\n", "Pokud nemáte nainstalovanou knihovnu plotly, odkomentujte a spusťte příslušné řádky." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# instalace plotly\n", "# %pip install plotly" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pro plotly express se vžila zkratka `px`, kterou použijeme i my. " ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "import plotly.express as px" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import plotly.io as pio\n", "\n", "# from https://github.com/microsoft/vscode-jupyter/issues/6999\n", "# This ensures Plotly output works in multiple places:\n", "# plotly_mimetype: VS Code notebook UI\n", "# notebook: \"Jupyter: Export to HTML\" command in VS Code\n", "# See https://plotly.com/python/renderers/#multiple-renderers\n", "pio.renderers.default = \"plotly_mimetype+notebook\"\n", "# notebook-only does not work in Jupyter Lab\n", "# pio.renderers.default = \"notebook\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interaktivní vizualizace dat\n", "\n", "Pojďme si zkusit trochu více prohlédnout data, se kterými jsme pracovali v předchozích lekcích na strojové učení." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Rybí míry\n", "\n", "Začněme rozměry ryb, na kterých jsme ukazovali regresi a klasifikaci. Určitě stojí za to si data nejprve trochu prohlédnout. (Jen si asi nenakreslíme přímo vzhled ryb, na to nám data nestačí :)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "fish_data = pd.read_csv(\"../data/fish_data.csv\", index_col=0)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "species_cs = {\n", " \"Bream\": \"Cejn\",\n", " \"Roach\": \"Plotice\",\n", " \"Whitefish\": \"Bílá ryba\",\n", " \"Parkki\": \"Karas\",\n", " \"Perch\": \"Okoun\",\n", " \"Pike\": \"Štika\",\n", " \"Smelt\": \"Koruška\",\n", "}\n", "fish_data = fish_data.assign(Species=fish_data[\"Species\"].map(species_cs))" ] }, { "cell_type": "code", "execution_count": 12, "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", " \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", " \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", "
SpeciesWeightLength1Length2Length3HeightWidthID
0Cejn242.023.225.430.011.52004.02000
1Cejn290.024.026.331.212.48004.30561
2Cejn340.023.926.531.112.37784.69612
3Cejn363.026.329.033.512.73004.45553
4Cejn430.026.529.034.012.44405.13404
...........................
153Koruška9.811.412.013.22.20441.1484153
154Koruška12.211.512.213.42.09041.3936154
155Koruška13.411.712.413.52.43001.2690155
156Koruška12.212.113.013.82.27701.2558156
158Koruška19.913.815.016.22.93221.8792158
\n", "

123 rows × 8 columns

\n", "
" ], "text/plain": [ " Species Weight Length1 Length2 Length3 Height Width ID\n", "0 Cejn 242.0 23.2 25.4 30.0 11.5200 4.0200 0\n", "1 Cejn 290.0 24.0 26.3 31.2 12.4800 4.3056 1\n", "2 Cejn 340.0 23.9 26.5 31.1 12.3778 4.6961 2\n", "3 Cejn 363.0 26.3 29.0 33.5 12.7300 4.4555 3\n", "4 Cejn 430.0 26.5 29.0 34.0 12.4440 5.1340 4\n", ".. ... ... ... ... ... ... ... ...\n", "153 Koruška 9.8 11.4 12.0 13.2 2.2044 1.1484 153\n", "154 Koruška 12.2 11.5 12.2 13.4 2.0904 1.3936 154\n", "155 Koruška 13.4 11.7 12.4 13.5 2.4300 1.2690 155\n", "156 Koruška 12.2 12.1 13.0 13.8 2.2770 1.2558 156\n", "158 Koruška 19.9 13.8 15.0 16.2 2.9322 1.8792 158\n", "\n", "[123 rows x 8 columns]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fish_data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A místo klasického zobrazování čísel si zkusíme rovnou data vykreslit do grafu. Víme (tušíme), že v datech je spousta sloupců. Můžeme si je nechat vykreslit všechny pomocí `scatter_matrix`." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "dimensions": [ { "axis": { "matches": true }, "label": "Species", "values": [ "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Bílá ryba", "Bílá ryba", "Bílá ryba", "Bílá ryba", "Karas", "Karas", "Karas", "Karas", "Karas", "Karas", "Karas", "Karas", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška" ] }, { "axis": { "matches": true }, "label": "Weight", "values": [ 242, 290, 340, 363, 430, 450, 390, 450, 500, 475, 500, 500, 340, 600, 600, 700, 700, 610, 575, 685, 725, 720, 714, 850, 1000, 955, 925, 975, 950, 40, 78, 87, 110, 120, 145, 160, 140, 200, 180, 290, 390, 270, 270, 540, 800, 55, 60, 120, 170, 145, 200, 273, 300, 40, 51.5, 70, 78, 80, 85, 85, 110, 125, 130, 120, 120, 130, 135, 130, 150, 145, 150, 225, 145, 197, 218, 300, 260, 265, 250, 514, 556, 840, 685, 700, 690, 900, 650, 820, 850, 900, 1015, 820, 1100, 1000, 1100, 200, 300, 300, 300, 430, 345, 456, 510, 540, 500, 567, 770, 1250, 1600, 1550, 6.7, 7.5, 7, 9.7, 9.8, 8.7, 10, 9.9, 9.8, 12.2, 13.4, 12.2, 19.9 ] }, { "axis": { "matches": true }, "label": "Length1", "values": [ 23.2, 24, 23.9, 26.3, 26.5, 26.8, 27.6, 27.6, 28.5, 28.4, 28.7, 29.1, 29.5, 29.4, 29.4, 30.4, 30.4, 30.9, 31.3, 31.4, 31.8, 32, 32.7, 32.8, 33.5, 35, 36.2, 37.4, 38, 12.9, 17.5, 18.2, 19.1, 19.4, 20.5, 20.5, 21, 22.1, 23.6, 24, 29.5, 23.6, 24.1, 28.5, 33.7, 13.5, 14.3, 17.5, 19, 19.8, 21.2, 23, 24, 13.8, 15, 15.7, 16.8, 17.2, 17.8, 18.2, 19, 19, 19.3, 20, 20, 20, 20, 20.5, 20.5, 20.7, 21, 22, 22, 23.5, 25, 25.2, 25.4, 25.4, 25.9, 30.5, 32, 32.5, 34, 34, 34.6, 36.5, 36.5, 36.6, 36.9, 37, 37, 37.1, 39, 39.8, 40.1, 30, 31.7, 32.7, 34.8, 35.5, 36, 40, 40, 40.1, 42, 43.2, 44.8, 52, 56, 56, 9.3, 10, 10.1, 10.4, 10.7, 10.8, 11.3, 11.3, 11.4, 11.5, 11.7, 12.1, 13.8 ] }, { "axis": { "matches": true }, "label": "Length2", "values": [ 25.4, 26.3, 26.5, 29, 29, 29.7, 30, 30, 30.7, 31, 31, 31.5, 32, 32, 32, 33, 33, 33.5, 34, 34, 35, 35, 36, 36, 37, 38.5, 39.5, 41, 41, 14.1, 18.8, 19.8, 20.8, 21, 22, 22.5, 22.5, 23.5, 25.2, 26, 31.7, 26, 26.5, 31, 36.4, 14.7, 15.5, 19, 20.7, 21.5, 23, 25, 26, 15, 16.2, 17.4, 18.7, 19, 19.6, 20, 21, 21, 21.3, 22, 22, 22, 22, 22.5, 22.5, 22.7, 23, 24, 24, 25.6, 26.5, 27.3, 27.5, 27.5, 28, 32.8, 34.5, 35, 36.5, 36, 37, 39, 39, 39, 40, 40, 40, 40, 42, 43, 43, 32.3, 34, 35, 37.3, 38, 38.5, 42.5, 42.5, 43, 45, 46, 48, 56, 60, 60, 9.8, 10.5, 10.6, 11, 11.2, 11.3, 11.8, 11.8, 12, 12.2, 12.4, 13, 15 ] }, { "axis": { "matches": true }, "label": "Length3", "values": [ 30, 31.2, 31.1, 33.5, 34, 34.7, 35, 35.1, 36.2, 36.2, 36.2, 36.4, 37.3, 37.2, 37.2, 38.3, 38.5, 38.6, 39.5, 39.2, 40.9, 40.6, 41.5, 41.6, 42.6, 44, 45.3, 45.9, 46.5, 16.2, 21.2, 22.2, 23.1, 23.7, 24.3, 25.3, 25, 26.8, 27.9, 29.2, 35, 28.7, 29.3, 34, 39.6, 16.5, 17.4, 21.3, 23.2, 24.1, 25.8, 28, 29, 16, 17.2, 18.5, 19.4, 20.2, 20.8, 21, 22.5, 22.5, 22.8, 23.5, 23.5, 23.5, 23.5, 24, 24, 24.2, 24.5, 25.5, 25.5, 27, 28, 28.7, 28.9, 28.9, 29.4, 34, 36.5, 37.3, 39, 38.3, 39.3, 41.4, 41.4, 41.3, 42.3, 42.5, 42.4, 42.5, 44.6, 45.2, 45.5, 34.8, 37.8, 38.8, 39.8, 40.5, 41, 45.5, 45.5, 45.8, 48, 48.7, 51.2, 59.7, 64, 64, 10.8, 11.6, 11.6, 12, 12.4, 12.6, 13.1, 13.1, 13.2, 13.4, 13.5, 13.8, 16.2 ] }, { "axis": { "matches": true }, "label": "Height", "values": [ 11.52, 12.48, 12.3778, 12.73, 12.444, 13.6024, 12.67, 14.0049, 14.2266, 14.2628, 14.3714, 13.7592, 13.9129, 14.9544, 15.438, 14.8604, 14.938, 15.633, 15.1285, 15.9936, 16.36, 16.3618, 16.517, 16.8896, 18.957, 18.084, 18.7542, 18.6354, 17.6235, 4.1472, 5.5756, 5.6166, 6.1677, 6.1146, 6.6339, 7.0334, 6.55, 7.3968, 7.0866, 8.8768, 9.485, 8.3804, 8.1454, 10.744000000000002, 11.7612, 6.8475, 6.5772, 8.3922, 9.396, 9.7364, 10.3458, 11.088, 11.368, 3.824, 4.5924, 4.588, 5.1992, 5.6358, 5.1376, 5.082, 5.6925, 5.6925, 6.384, 6.11, 5.64, 6.11, 5.875, 5.856, 6.792000000000001, 5.9532, 5.2185, 7.292999999999999, 6.375, 6.561, 7.167999999999999, 8.323, 7.1672, 7.0516, 7.8204, 10.03, 10.2565, 11.4884, 10.880999999999998, 10.6091, 10.5717, 11.1366, 11.1366, 12.4313, 11.9286, 11.73, 12.3808, 11.135, 12.8002, 11.9328, 12.5125, 5.568, 5.7078, 5.9364, 6.2884, 7.29, 6.396, 7.28, 6.825, 7.786, 6.96, 7.792000000000001, 7.68, 10.6863, 9.6, 9.6, 1.7388, 1.972, 1.7284, 2.196, 2.0832, 1.9782, 2.2139, 2.2139, 2.2044, 2.0904, 2.43, 2.277, 2.9322 ] }, { "axis": { "matches": true }, "label": "Width", "values": [ 4.02, 4.3056, 4.6961, 4.4555, 5.134, 4.9274, 4.69, 4.8438, 4.9594, 5.1042, 4.8146, 4.368, 5.0728, 5.1708, 5.58, 5.2854, 5.1975, 5.1338, 5.5695, 5.3704, 6.0532, 6.09, 5.8515, 6.1984, 6.603, 6.292000000000001, 6.7497, 6.7473, 6.3705, 2.268, 2.9044, 3.1746, 3.3957, 3.2943, 3.5478, 3.8203, 3.325, 4.1272, 3.906, 4.4968, 5.355, 4.2476, 4.2485, 6.562, 6.5736, 2.3265, 2.3142, 2.9181, 3.4104, 3.1571, 3.6636, 4.144, 4.234, 2.432, 2.6316, 2.9415, 3.1234, 3.0502, 3.0368, 2.772, 3.555, 3.6675, 3.534, 3.4075, 3.525, 3.525, 3.525, 3.624, 3.624, 3.63, 3.626, 3.723, 3.825, 4.239, 4.144, 5.1373, 4.335, 4.335, 4.2042, 6.018, 6.3875, 7.7957, 6.864, 6.7408, 6.3666, 7.4934, 6.002999999999999, 7.3514, 7.1064, 7.225, 7.4624, 6.63, 6.8684, 7.2772, 7.4165, 3.3756, 4.158, 4.3844, 4.0198, 4.5765, 3.977, 4.3225, 4.459, 5.1296, 4.896, 4.87, 5.376, 6.9849, 6.144, 6.144, 1.0476, 1.16, 1.1484, 1.38, 1.2772, 1.2852, 1.2838, 1.1659, 1.1484, 1.3936, 1.269, 1.2558, 1.8792 ] }, { "axis": { "matches": true }, "label": "ID", "values": [ 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 37, 38, 41, 42, 44, 45, 46, 50, 51, 52, 54, 55, 56, 58, 59, 61, 62, 64, 67, 68, 69, 70, 71, 74, 75, 76, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 96, 97, 100, 101, 102, 103, 104, 106, 109, 110, 111, 112, 113, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 141, 142, 143, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 158 ] } ], "hovertemplate": "%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "", "marker": { "color": "#636efa", "symbol": "circle" }, "name": "", "showlegend": false, "type": "splom" } ], "layout": { "dragmode": "select", "legend": { "tracegroupgap": 0 }, "margin": { "t": 60 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "px.scatter_matrix(fish_data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To vůbec není špatné na prvotní orientaci. Už teď je vidět, že tam máme kategorickou proměnnou Species, nějaké spojité proměnné s rozměry a nepodstatné ID. Vidíme také, že některé proměnné spolu hodně korelují. \n", "\n", "Už teď bychom mohli využít interaktivních prvků: zkuste si najet kurzorem na body v grafu nebo použít nástroje na změnu měřítka nebo výběr dat, které se zobrazí v pravém horním rohu. Ještě lepší bude ale trochu graf zlepšit: Zahodit ID a druhy si označit barvou." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "customdata": [ [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ], [ "Cejn" ] ], "dimensions": [ { "axis": { "matches": true }, "label": "Weight", "values": [ 242, 290, 340, 363, 430, 450, 390, 450, 500, 475, 500, 500, 340, 600, 600, 700, 700, 610, 575, 685, 725, 720, 714, 850, 1000, 955, 925, 975, 950 ] }, { "axis": { "matches": true }, "label": "Length1", "values": [ 23.2, 24, 23.9, 26.3, 26.5, 26.8, 27.6, 27.6, 28.5, 28.4, 28.7, 29.1, 29.5, 29.4, 29.4, 30.4, 30.4, 30.9, 31.3, 31.4, 31.8, 32, 32.7, 32.8, 33.5, 35, 36.2, 37.4, 38 ] }, { "axis": { "matches": true }, "label": "Length2", "values": [ 25.4, 26.3, 26.5, 29, 29, 29.7, 30, 30, 30.7, 31, 31, 31.5, 32, 32, 32, 33, 33, 33.5, 34, 34, 35, 35, 36, 36, 37, 38.5, 39.5, 41, 41 ] }, { "axis": { "matches": true }, "label": "Length3", "values": [ 30, 31.2, 31.1, 33.5, 34, 34.7, 35, 35.1, 36.2, 36.2, 36.2, 36.4, 37.3, 37.2, 37.2, 38.3, 38.5, 38.6, 39.5, 39.2, 40.9, 40.6, 41.5, 41.6, 42.6, 44, 45.3, 45.9, 46.5 ] }, { "axis": { "matches": true }, "label": "Height", "values": [ 11.52, 12.48, 12.3778, 12.73, 12.444, 13.6024, 12.67, 14.0049, 14.2266, 14.2628, 14.3714, 13.7592, 13.9129, 14.9544, 15.438, 14.8604, 14.938, 15.633, 15.1285, 15.9936, 16.36, 16.3618, 16.517, 16.8896, 18.957, 18.084, 18.7542, 18.6354, 17.6235 ] }, { "axis": { "matches": true }, "label": "Width", "values": [ 4.02, 4.3056, 4.6961, 4.4555, 5.134, 4.9274, 4.69, 4.8438, 4.9594, 5.1042, 4.8146, 4.368, 5.0728, 5.1708, 5.58, 5.2854, 5.1975, 5.1338, 5.5695, 5.3704, 6.0532, 6.09, 5.8515, 6.1984, 6.603, 6.292000000000001, 6.7497, 6.7473, 6.3705 ] } ], "hovertemplate": "Species=%{customdata[0]}
%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "Cejn", "marker": { "color": "#636efa", "opacity": 1, "symbol": "circle" }, "name": "Cejn", "showlegend": true, "type": "splom" }, { "customdata": [ [ "Plotice" ], [ "Plotice" ], [ "Plotice" ], [ "Plotice" ], [ "Plotice" ], [ "Plotice" ], [ "Plotice" ], [ "Plotice" ], [ "Plotice" ], [ "Plotice" ], [ "Plotice" ], [ "Plotice" ] ], "dimensions": [ { "axis": { "matches": true }, "label": "Weight", "values": [ 40, 78, 87, 110, 120, 145, 160, 140, 200, 180, 290, 390 ] }, { "axis": { "matches": true }, "label": "Length1", "values": [ 12.9, 17.5, 18.2, 19.1, 19.4, 20.5, 20.5, 21, 22.1, 23.6, 24, 29.5 ] }, { "axis": { "matches": true }, "label": "Length2", "values": [ 14.1, 18.8, 19.8, 20.8, 21, 22, 22.5, 22.5, 23.5, 25.2, 26, 31.7 ] }, { "axis": { "matches": true }, "label": "Length3", "values": [ 16.2, 21.2, 22.2, 23.1, 23.7, 24.3, 25.3, 25, 26.8, 27.9, 29.2, 35 ] }, { "axis": { "matches": true }, "label": "Height", "values": [ 4.1472, 5.5756, 5.6166, 6.1677, 6.1146, 6.6339, 7.0334, 6.55, 7.3968, 7.0866, 8.8768, 9.485 ] }, { "axis": { "matches": true }, "label": "Width", "values": [ 2.268, 2.9044, 3.1746, 3.3957, 3.2943, 3.5478, 3.8203, 3.325, 4.1272, 3.906, 4.4968, 5.355 ] } ], "hovertemplate": "Species=%{customdata[0]}
%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "Plotice", "marker": { "color": "#EF553B", "opacity": 1, "symbol": "circle" }, "name": "Plotice", "showlegend": true, "type": "splom" }, { "customdata": [ [ "Bílá ryba" ], [ "Bílá ryba" ], [ "Bílá ryba" ], [ "Bílá ryba" ] ], "dimensions": [ { "axis": { "matches": true }, "label": "Weight", "values": [ 270, 270, 540, 800 ] }, { "axis": { "matches": true }, "label": "Length1", "values": [ 23.6, 24.1, 28.5, 33.7 ] }, { "axis": { "matches": true }, "label": "Length2", "values": [ 26, 26.5, 31, 36.4 ] }, { "axis": { "matches": true }, "label": "Length3", "values": [ 28.7, 29.3, 34, 39.6 ] }, { "axis": { "matches": true }, "label": "Height", "values": [ 8.3804, 8.1454, 10.744000000000002, 11.7612 ] }, { "axis": { "matches": true }, "label": "Width", "values": [ 4.2476, 4.2485, 6.562, 6.5736 ] } ], "hovertemplate": "Species=%{customdata[0]}
%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "Bílá ryba", "marker": { "color": "#00cc96", "opacity": 1, "symbol": "circle" }, "name": "Bílá ryba", "showlegend": true, "type": "splom" }, { "customdata": [ [ "Karas" ], [ "Karas" ], [ "Karas" ], [ "Karas" ], [ "Karas" ], [ "Karas" ], [ "Karas" ], [ "Karas" ] ], "dimensions": [ { "axis": { "matches": true }, "label": "Weight", "values": [ 55, 60, 120, 170, 145, 200, 273, 300 ] }, { "axis": { "matches": true }, "label": "Length1", "values": [ 13.5, 14.3, 17.5, 19, 19.8, 21.2, 23, 24 ] }, { "axis": { "matches": true }, "label": "Length2", "values": [ 14.7, 15.5, 19, 20.7, 21.5, 23, 25, 26 ] }, { "axis": { "matches": true }, "label": "Length3", "values": [ 16.5, 17.4, 21.3, 23.2, 24.1, 25.8, 28, 29 ] }, { "axis": { "matches": true }, "label": "Height", "values": [ 6.8475, 6.5772, 8.3922, 9.396, 9.7364, 10.3458, 11.088, 11.368 ] }, { "axis": { "matches": true }, "label": "Width", "values": [ 2.3265, 2.3142, 2.9181, 3.4104, 3.1571, 3.6636, 4.144, 4.234 ] } ], "hovertemplate": "Species=%{customdata[0]}
%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "Karas", "marker": { "color": "#ab63fa", "opacity": 1, "symbol": "circle" }, "name": "Karas", "showlegend": true, "type": "splom" }, { "customdata": [ [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ], [ "Okoun" ] ], "dimensions": [ { "axis": { "matches": true }, "label": "Weight", "values": [ 40, 51.5, 70, 78, 80, 85, 85, 110, 125, 130, 120, 120, 130, 135, 130, 150, 145, 150, 225, 145, 197, 218, 300, 260, 265, 250, 514, 556, 840, 685, 700, 690, 900, 650, 820, 850, 900, 1015, 820, 1100, 1000, 1100 ] }, { "axis": { "matches": true }, "label": "Length1", "values": [ 13.8, 15, 15.7, 16.8, 17.2, 17.8, 18.2, 19, 19, 19.3, 20, 20, 20, 20, 20.5, 20.5, 20.7, 21, 22, 22, 23.5, 25, 25.2, 25.4, 25.4, 25.9, 30.5, 32, 32.5, 34, 34, 34.6, 36.5, 36.5, 36.6, 36.9, 37, 37, 37.1, 39, 39.8, 40.1 ] }, { "axis": { "matches": true }, "label": "Length2", "values": [ 15, 16.2, 17.4, 18.7, 19, 19.6, 20, 21, 21, 21.3, 22, 22, 22, 22, 22.5, 22.5, 22.7, 23, 24, 24, 25.6, 26.5, 27.3, 27.5, 27.5, 28, 32.8, 34.5, 35, 36.5, 36, 37, 39, 39, 39, 40, 40, 40, 40, 42, 43, 43 ] }, { "axis": { "matches": true }, "label": "Length3", "values": [ 16, 17.2, 18.5, 19.4, 20.2, 20.8, 21, 22.5, 22.5, 22.8, 23.5, 23.5, 23.5, 23.5, 24, 24, 24.2, 24.5, 25.5, 25.5, 27, 28, 28.7, 28.9, 28.9, 29.4, 34, 36.5, 37.3, 39, 38.3, 39.3, 41.4, 41.4, 41.3, 42.3, 42.5, 42.4, 42.5, 44.6, 45.2, 45.5 ] }, { "axis": { "matches": true }, "label": "Height", "values": [ 3.824, 4.5924, 4.588, 5.1992, 5.6358, 5.1376, 5.082, 5.6925, 5.6925, 6.384, 6.11, 5.64, 6.11, 5.875, 5.856, 6.792000000000001, 5.9532, 5.2185, 7.292999999999999, 6.375, 6.561, 7.167999999999999, 8.323, 7.1672, 7.0516, 7.8204, 10.03, 10.2565, 11.4884, 10.880999999999998, 10.6091, 10.5717, 11.1366, 11.1366, 12.4313, 11.9286, 11.73, 12.3808, 11.135, 12.8002, 11.9328, 12.5125 ] }, { "axis": { "matches": true }, "label": "Width", "values": [ 2.432, 2.6316, 2.9415, 3.1234, 3.0502, 3.0368, 2.772, 3.555, 3.6675, 3.534, 3.4075, 3.525, 3.525, 3.525, 3.624, 3.624, 3.63, 3.626, 3.723, 3.825, 4.239, 4.144, 5.1373, 4.335, 4.335, 4.2042, 6.018, 6.3875, 7.7957, 6.864, 6.7408, 6.3666, 7.4934, 6.002999999999999, 7.3514, 7.1064, 7.225, 7.4624, 6.63, 6.8684, 7.2772, 7.4165 ] } ], "hovertemplate": "Species=%{customdata[0]}
%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "Okoun", "marker": { "color": "#FFA15A", "opacity": 1, "symbol": "circle" }, "name": "Okoun", "showlegend": true, "type": "splom" }, { "customdata": [ [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ], [ "Štika" ] ], "dimensions": [ { "axis": { "matches": true }, "label": "Weight", "values": [ 200, 300, 300, 300, 430, 345, 456, 510, 540, 500, 567, 770, 1250, 1600, 1550 ] }, { "axis": { "matches": true }, "label": "Length1", "values": [ 30, 31.7, 32.7, 34.8, 35.5, 36, 40, 40, 40.1, 42, 43.2, 44.8, 52, 56, 56 ] }, { "axis": { "matches": true }, "label": "Length2", "values": [ 32.3, 34, 35, 37.3, 38, 38.5, 42.5, 42.5, 43, 45, 46, 48, 56, 60, 60 ] }, { "axis": { "matches": true }, "label": "Length3", "values": [ 34.8, 37.8, 38.8, 39.8, 40.5, 41, 45.5, 45.5, 45.8, 48, 48.7, 51.2, 59.7, 64, 64 ] }, { "axis": { "matches": true }, "label": "Height", "values": [ 5.568, 5.7078, 5.9364, 6.2884, 7.29, 6.396, 7.28, 6.825, 7.786, 6.96, 7.792000000000001, 7.68, 10.6863, 9.6, 9.6 ] }, { "axis": { "matches": true }, "label": "Width", "values": [ 3.3756, 4.158, 4.3844, 4.0198, 4.5765, 3.977, 4.3225, 4.459, 5.1296, 4.896, 4.87, 5.376, 6.9849, 6.144, 6.144 ] } ], "hovertemplate": "Species=%{customdata[0]}
%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "Štika", "marker": { "color": "#19d3f3", "opacity": 1, "symbol": "circle" }, "name": "Štika", "showlegend": true, "type": "splom" }, { "customdata": [ [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ], [ "Koruška" ] ], "dimensions": [ { "axis": { "matches": true }, "label": "Weight", "values": [ 6.7, 7.5, 7, 9.7, 9.8, 8.7, 10, 9.9, 9.8, 12.2, 13.4, 12.2, 19.9 ] }, { "axis": { "matches": true }, "label": "Length1", "values": [ 9.3, 10, 10.1, 10.4, 10.7, 10.8, 11.3, 11.3, 11.4, 11.5, 11.7, 12.1, 13.8 ] }, { "axis": { "matches": true }, "label": "Length2", "values": [ 9.8, 10.5, 10.6, 11, 11.2, 11.3, 11.8, 11.8, 12, 12.2, 12.4, 13, 15 ] }, { "axis": { "matches": true }, "label": "Length3", "values": [ 10.8, 11.6, 11.6, 12, 12.4, 12.6, 13.1, 13.1, 13.2, 13.4, 13.5, 13.8, 16.2 ] }, { "axis": { "matches": true }, "label": "Height", "values": [ 1.7388, 1.972, 1.7284, 2.196, 2.0832, 1.9782, 2.2139, 2.2139, 2.2044, 2.0904, 2.43, 2.277, 2.9322 ] }, { "axis": { "matches": true }, "label": "Width", "values": [ 1.0476, 1.16, 1.1484, 1.38, 1.2772, 1.2852, 1.2838, 1.1659, 1.1484, 1.3936, 1.269, 1.2558, 1.8792 ] } ], "hovertemplate": "Species=%{customdata[0]}
%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "Koruška", "marker": { "color": "#FF6692", "opacity": 1, "symbol": "circle" }, "name": "Koruška", "showlegend": true, "type": "splom" } ], "layout": { "dragmode": "select", "legend": { "title": { "text": "Species" }, "tracegroupgap": 0 }, "margin": { "t": 60 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "px.scatter_matrix(\n", " fish_data,\n", " dimensions=[\"Weight\", \"Length1\", \"Length2\", \"Length3\", \"Height\", \"Width\"],\n", " color=\"Species\",\n", " opacity=1,\n", " hover_data=[\"Species\"],\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tady nám kromě barevnosti přibyla vpravo legenda. A dokonce legenda interaktivní! Jednoduchým kliknutím můžeme schovat / zobrazit jednotlivé kategorie, dvouklikem můžeme zobrazit jen jednu kategorii. Zkuste si to! Užitečné může být i vybírání dat - Box Select nebo Lasso Select. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Úkol:** Použijte pro barvu sloupec Weight, symboly udělejte částečně průhledné pomocí argumentu `opacity` (rozsah 0 - 1) a v legendě, zobrazované, když se najede kurzorem na určitý bod, nechť se zobrzují všechny sloupce (pomůže argument `hover_data`)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Když se pak chceme třeba podívat na statistické vlastnosti jedné konkrétní proměnné (sloupce), můžeme použít některou z funkcí na zobrazení rozdělovací funkce, resp. některých jejích vlastností (momentů).\n", "\n", "Začít můžeme poměrně častým box plotem. Bonus plotly je hlavně v interaktivním zobrazení číselných hodnot: mediánu a kvantilů, a také identifikaci (pravděpodobně) odlehlých hodnot." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "alignmentgroup": "True", "boxpoints": "all", "hovertemplate": "Species=%{x}
Height=%{y}", "legendgroup": "Cejn", "marker": { "color": "#636efa" }, "name": "Cejn", "notched": false, "offsetgroup": "Cejn", "orientation": "v", "showlegend": true, "type": "box", "x": [ "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn", "Cejn" ], "x0": " ", "xaxis": "x", "y": [ 11.52, 12.48, 12.3778, 12.73, 12.444, 13.6024, 12.67, 14.0049, 14.2266, 14.2628, 14.3714, 13.7592, 13.9129, 14.9544, 15.438, 14.8604, 14.938, 15.633, 15.1285, 15.9936, 16.36, 16.3618, 16.517, 16.8896, 18.957, 18.084, 18.7542, 18.6354, 17.6235 ], "y0": " ", "yaxis": "y" }, { "alignmentgroup": "True", "boxpoints": "all", "hovertemplate": "Species=%{x}
Height=%{y}", "legendgroup": "Plotice", "marker": { "color": "#EF553B" }, "name": "Plotice", "notched": false, "offsetgroup": "Plotice", "orientation": "v", "showlegend": true, "type": "box", "x": [ "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice", "Plotice" ], "x0": " ", "xaxis": "x", "y": [ 4.1472, 5.5756, 5.6166, 6.1677, 6.1146, 6.6339, 7.0334, 6.55, 7.3968, 7.0866, 8.8768, 9.485 ], "y0": " ", "yaxis": "y" }, { "alignmentgroup": "True", "boxpoints": "all", "hovertemplate": "Species=%{x}
Height=%{y}", "legendgroup": "Bílá ryba", "marker": { "color": "#00cc96" }, "name": "Bílá ryba", "notched": false, "offsetgroup": "Bílá ryba", "orientation": "v", "showlegend": true, "type": "box", "x": [ "Bílá ryba", "Bílá ryba", "Bílá ryba", "Bílá ryba" ], "x0": " ", "xaxis": "x", "y": [ 8.3804, 8.1454, 10.744000000000002, 11.7612 ], "y0": " ", "yaxis": "y" }, { "alignmentgroup": "True", "boxpoints": "all", "hovertemplate": "Species=%{x}
Height=%{y}", "legendgroup": "Karas", "marker": { "color": "#ab63fa" }, "name": "Karas", "notched": false, "offsetgroup": "Karas", "orientation": "v", "showlegend": true, "type": "box", "x": [ "Karas", "Karas", "Karas", "Karas", "Karas", "Karas", "Karas", "Karas" ], "x0": " ", "xaxis": "x", "y": [ 6.8475, 6.5772, 8.3922, 9.396, 9.7364, 10.3458, 11.088, 11.368 ], "y0": " ", "yaxis": "y" }, { "alignmentgroup": "True", "boxpoints": "all", "hovertemplate": "Species=%{x}
Height=%{y}", "legendgroup": "Okoun", "marker": { "color": "#FFA15A" }, "name": "Okoun", "notched": false, "offsetgroup": "Okoun", "orientation": "v", "showlegend": true, "type": "box", "x": [ "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun", "Okoun" ], "x0": " ", "xaxis": "x", "y": [ 3.824, 4.5924, 4.588, 5.1992, 5.6358, 5.1376, 5.082, 5.6925, 5.6925, 6.384, 6.11, 5.64, 6.11, 5.875, 5.856, 6.792000000000001, 5.9532, 5.2185, 7.292999999999999, 6.375, 6.561, 7.167999999999999, 8.323, 7.1672, 7.0516, 7.8204, 10.03, 10.2565, 11.4884, 10.880999999999998, 10.6091, 10.5717, 11.1366, 11.1366, 12.4313, 11.9286, 11.73, 12.3808, 11.135, 12.8002, 11.9328, 12.5125 ], "y0": " ", "yaxis": "y" }, { "alignmentgroup": "True", "boxpoints": "all", "hovertemplate": "Species=%{x}
Height=%{y}", "legendgroup": "Štika", "marker": { "color": "#19d3f3" }, "name": "Štika", "notched": false, "offsetgroup": "Štika", "orientation": "v", "showlegend": true, "type": "box", "x": [ "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika", "Štika" ], "x0": " ", "xaxis": "x", "y": [ 5.568, 5.7078, 5.9364, 6.2884, 7.29, 6.396, 7.28, 6.825, 7.786, 6.96, 7.792000000000001, 7.68, 10.6863, 9.6, 9.6 ], "y0": " ", "yaxis": "y" }, { "alignmentgroup": "True", "boxpoints": "all", "hovertemplate": "Species=%{x}
Height=%{y}", "legendgroup": "Koruška", "marker": { "color": "#FF6692" }, "name": "Koruška", "notched": false, "offsetgroup": "Koruška", "orientation": "v", "showlegend": true, "type": "box", "x": [ "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška", "Koruška" ], "x0": " ", "xaxis": "x", "y": [ 1.7388, 1.972, 1.7284, 2.196, 2.0832, 1.9782, 2.2139, 2.2139, 2.2044, 2.0904, 2.43, 2.277, 2.9322 ], "y0": " ", "yaxis": "y" } ], "layout": { "boxmode": "overlay", "legend": { "title": { "text": "Species" }, "tracegroupgap": 0 }, "margin": { "t": 60 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "xaxis": { "anchor": "y", "categoryarray": [ "Cejn", "Plotice", "Bílá ryba", "Karas", "Okoun", "Štika", "Koruška" ], "categoryorder": "array", "domain": [ 0, 1 ], "title": { "text": "Species" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "Height" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "px.box(fish_data, x=\"Species\", color=\"Species\", y=\"Height\", points=\"all\", notched=False)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Cejn
Height=%{x}
count=%{y}", "legendgroup": "Cejn", "marker": { "color": "#636efa", "opacity": 0.5, "pattern": { "shape": "" } }, "name": "Cejn", "offsetgroup": "Cejn", "orientation": "v", "showlegend": true, "type": "histogram", "x": [ 11.52, 12.48, 12.3778, 12.73, 12.444, 13.6024, 12.67, 14.0049, 14.2266, 14.2628, 14.3714, 13.7592, 13.9129, 14.9544, 15.438, 14.8604, 14.938, 15.633, 15.1285, 15.9936, 16.36, 16.3618, 16.517, 16.8896, 18.957, 18.084, 18.7542, 18.6354, 17.6235 ], "xaxis": "x", "yaxis": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Plotice
Height=%{x}
count=%{y}", "legendgroup": "Plotice", "marker": { "color": "#EF553B", "opacity": 0.5, "pattern": { "shape": "" } }, "name": "Plotice", "offsetgroup": "Plotice", "orientation": "v", "showlegend": true, "type": "histogram", "x": [ 4.1472, 5.5756, 5.6166, 6.1677, 6.1146, 6.6339, 7.0334, 6.55, 7.3968, 7.0866, 8.8768, 9.485 ], "xaxis": "x", "yaxis": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Bílá ryba
Height=%{x}
count=%{y}", "legendgroup": "Bílá ryba", "marker": { "color": "#00cc96", "opacity": 0.5, "pattern": { "shape": "" } }, "name": "Bílá ryba", "offsetgroup": "Bílá ryba", "orientation": "v", "showlegend": true, "type": "histogram", "x": [ 8.3804, 8.1454, 10.744000000000002, 11.7612 ], "xaxis": "x", "yaxis": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Karas
Height=%{x}
count=%{y}", "legendgroup": "Karas", "marker": { "color": "#ab63fa", "opacity": 0.5, "pattern": { "shape": "" } }, "name": "Karas", "offsetgroup": "Karas", "orientation": "v", "showlegend": true, "type": "histogram", "x": [ 6.8475, 6.5772, 8.3922, 9.396, 9.7364, 10.3458, 11.088, 11.368 ], "xaxis": "x", "yaxis": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Okoun
Height=%{x}
count=%{y}", "legendgroup": "Okoun", "marker": { "color": "#FFA15A", "opacity": 0.5, "pattern": { "shape": "" } }, "name": "Okoun", "offsetgroup": "Okoun", "orientation": "v", "showlegend": true, "type": "histogram", "x": [ 3.824, 4.5924, 4.588, 5.1992, 5.6358, 5.1376, 5.082, 5.6925, 5.6925, 6.384, 6.11, 5.64, 6.11, 5.875, 5.856, 6.792000000000001, 5.9532, 5.2185, 7.292999999999999, 6.375, 6.561, 7.167999999999999, 8.323, 7.1672, 7.0516, 7.8204, 10.03, 10.2565, 11.4884, 10.880999999999998, 10.6091, 10.5717, 11.1366, 11.1366, 12.4313, 11.9286, 11.73, 12.3808, 11.135, 12.8002, 11.9328, 12.5125 ], "xaxis": "x", "yaxis": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Štika
Height=%{x}
count=%{y}", "legendgroup": "Štika", "marker": { "color": "#19d3f3", "opacity": 0.5, "pattern": { "shape": "" } }, "name": "Štika", "offsetgroup": "Štika", "orientation": "v", "showlegend": true, "type": "histogram", "x": [ 5.568, 5.7078, 5.9364, 6.2884, 7.29, 6.396, 7.28, 6.825, 7.786, 6.96, 7.792000000000001, 7.68, 10.6863, 9.6, 9.6 ], "xaxis": "x", "yaxis": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Koruška
Height=%{x}
count=%{y}", "legendgroup": "Koruška", "marker": { "color": "#FF6692", "opacity": 0.5, "pattern": { "shape": "" } }, "name": "Koruška", "offsetgroup": "Koruška", "orientation": "v", "showlegend": true, "type": "histogram", "x": [ 1.7388, 1.972, 1.7284, 2.196, 2.0832, 1.9782, 2.2139, 2.2139, 2.2044, 2.0904, 2.43, 2.277, 2.9322 ], "xaxis": "x", "yaxis": "y" } ], "layout": { "barmode": "relative", "legend": { "title": { "text": "Species" }, "tracegroupgap": 0 }, "margin": { "t": 60 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "Height" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "count" } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "px.histogram(fish_data, color=\"Species\", x=\"Height\", opacity=0.5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pro zobrazení vztahu dvou proměnných může být ještě užitečné podívat se na hustotu bodů v ploše pomocí kontur. U tohoto grafu můžeme po stranách zobrazit i tzv. marginální rozdělení: nejpravděpodobnější rozdělení jedné proměnné v závislosti na druhé." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "contours": { "coloring": "none" }, "hovertemplate": "Species=Cejn
Height=%{x}
Width=%{y}
count=%{z}", "legendgroup": "Cejn", "line": { "color": "#636efa" }, "name": "Cejn", "showlegend": true, "type": "histogram2dcontour", "x": [ 11.52, 12.48, 12.3778, 12.73, 12.444, 13.6024, 12.67, 14.0049, 14.2266, 14.2628, 14.3714, 13.7592, 13.9129, 14.9544, 15.438, 14.8604, 14.938, 15.633, 15.1285, 15.9936, 16.36, 16.3618, 16.517, 16.8896, 18.957, 18.084, 18.7542, 18.6354, 17.6235 ], "xaxis": "x", "xbingroup": "x", "y": [ 4.02, 4.3056, 4.6961, 4.4555, 5.134, 4.9274, 4.69, 4.8438, 4.9594, 5.1042, 4.8146, 4.368, 5.0728, 5.1708, 5.58, 5.2854, 5.1975, 5.1338, 5.5695, 5.3704, 6.0532, 6.09, 5.8515, 6.1984, 6.603, 6.292000000000001, 6.7497, 6.7473, 6.3705 ], "yaxis": "y", "ybingroup": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Cejn
Height=%{x}
count=%{y}", "legendgroup": "Cejn", "marker": { "color": "#636efa" }, "name": "Cejn", "offsetgroup": "Cejn", "opacity": 0.5, "showlegend": false, "type": "histogram", "x": [ 11.52, 12.48, 12.3778, 12.73, 12.444, 13.6024, 12.67, 14.0049, 14.2266, 14.2628, 14.3714, 13.7592, 13.9129, 14.9544, 15.438, 14.8604, 14.938, 15.633, 15.1285, 15.9936, 16.36, 16.3618, 16.517, 16.8896, 18.957, 18.084, 18.7542, 18.6354, 17.6235 ], "xaxis": "x3", "yaxis": "y3" }, { "alignmentgroup": "True", "bingroup": "y", "hovertemplate": "Species=Cejn
Width=%{y}
count=%{x}", "legendgroup": "Cejn", "marker": { "color": "#636efa" }, "name": "Cejn", "offsetgroup": "Cejn", "opacity": 0.5, "showlegend": false, "type": "histogram", "xaxis": "x2", "y": [ 4.02, 4.3056, 4.6961, 4.4555, 5.134, 4.9274, 4.69, 4.8438, 4.9594, 5.1042, 4.8146, 4.368, 5.0728, 5.1708, 5.58, 5.2854, 5.1975, 5.1338, 5.5695, 5.3704, 6.0532, 6.09, 5.8515, 6.1984, 6.603, 6.292000000000001, 6.7497, 6.7473, 6.3705 ], "yaxis": "y2" }, { "contours": { "coloring": "none" }, "hovertemplate": "Species=Plotice
Height=%{x}
Width=%{y}
count=%{z}", "legendgroup": "Plotice", "line": { "color": "#EF553B" }, "name": "Plotice", "showlegend": true, "type": "histogram2dcontour", "x": [ 4.1472, 5.5756, 5.6166, 6.1677, 6.1146, 6.6339, 7.0334, 6.55, 7.3968, 7.0866, 8.8768, 9.485 ], "xaxis": "x", "xbingroup": "x", "y": [ 2.268, 2.9044, 3.1746, 3.3957, 3.2943, 3.5478, 3.8203, 3.325, 4.1272, 3.906, 4.4968, 5.355 ], "yaxis": "y", "ybingroup": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Plotice
Height=%{x}
count=%{y}", "legendgroup": "Plotice", "marker": { "color": "#EF553B" }, "name": "Plotice", "offsetgroup": "Plotice", "opacity": 0.5, "showlegend": false, "type": "histogram", "x": [ 4.1472, 5.5756, 5.6166, 6.1677, 6.1146, 6.6339, 7.0334, 6.55, 7.3968, 7.0866, 8.8768, 9.485 ], "xaxis": "x3", "yaxis": "y3" }, { "alignmentgroup": "True", "bingroup": "y", "hovertemplate": "Species=Plotice
Width=%{y}
count=%{x}", "legendgroup": "Plotice", "marker": { "color": "#EF553B" }, "name": "Plotice", "offsetgroup": "Plotice", "opacity": 0.5, "showlegend": false, "type": "histogram", "xaxis": "x2", "y": [ 2.268, 2.9044, 3.1746, 3.3957, 3.2943, 3.5478, 3.8203, 3.325, 4.1272, 3.906, 4.4968, 5.355 ], "yaxis": "y2" }, { "contours": { "coloring": "none" }, "hovertemplate": "Species=Bílá ryba
Height=%{x}
Width=%{y}
count=%{z}", "legendgroup": "Bílá ryba", "line": { "color": "#00cc96" }, "name": "Bílá ryba", "showlegend": true, "type": "histogram2dcontour", "x": [ 8.3804, 8.1454, 10.744000000000002, 11.7612 ], "xaxis": "x", "xbingroup": "x", "y": [ 4.2476, 4.2485, 6.562, 6.5736 ], "yaxis": "y", "ybingroup": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Bílá ryba
Height=%{x}
count=%{y}", "legendgroup": "Bílá ryba", "marker": { "color": "#00cc96" }, "name": "Bílá ryba", "offsetgroup": "Bílá ryba", "opacity": 0.5, "showlegend": false, "type": "histogram", "x": [ 8.3804, 8.1454, 10.744000000000002, 11.7612 ], "xaxis": "x3", "yaxis": "y3" }, { "alignmentgroup": "True", "bingroup": "y", "hovertemplate": "Species=Bílá ryba
Width=%{y}
count=%{x}", "legendgroup": "Bílá ryba", "marker": { "color": "#00cc96" }, "name": "Bílá ryba", "offsetgroup": "Bílá ryba", "opacity": 0.5, "showlegend": false, "type": "histogram", "xaxis": "x2", "y": [ 4.2476, 4.2485, 6.562, 6.5736 ], "yaxis": "y2" }, { "contours": { "coloring": "none" }, "hovertemplate": "Species=Karas
Height=%{x}
Width=%{y}
count=%{z}", "legendgroup": "Karas", "line": { "color": "#ab63fa" }, "name": "Karas", "showlegend": true, "type": "histogram2dcontour", "x": [ 6.8475, 6.5772, 8.3922, 9.396, 9.7364, 10.3458, 11.088, 11.368 ], "xaxis": "x", "xbingroup": "x", "y": [ 2.3265, 2.3142, 2.9181, 3.4104, 3.1571, 3.6636, 4.144, 4.234 ], "yaxis": "y", "ybingroup": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Karas
Height=%{x}
count=%{y}", "legendgroup": "Karas", "marker": { "color": "#ab63fa" }, "name": "Karas", "offsetgroup": "Karas", "opacity": 0.5, "showlegend": false, "type": "histogram", "x": [ 6.8475, 6.5772, 8.3922, 9.396, 9.7364, 10.3458, 11.088, 11.368 ], "xaxis": "x3", "yaxis": "y3" }, { "alignmentgroup": "True", "bingroup": "y", "hovertemplate": "Species=Karas
Width=%{y}
count=%{x}", "legendgroup": "Karas", "marker": { "color": "#ab63fa" }, "name": "Karas", "offsetgroup": "Karas", "opacity": 0.5, "showlegend": false, "type": "histogram", "xaxis": "x2", "y": [ 2.3265, 2.3142, 2.9181, 3.4104, 3.1571, 3.6636, 4.144, 4.234 ], "yaxis": "y2" }, { "contours": { "coloring": "none" }, "hovertemplate": "Species=Okoun
Height=%{x}
Width=%{y}
count=%{z}", "legendgroup": "Okoun", "line": { "color": "#FFA15A" }, "name": "Okoun", "showlegend": true, "type": "histogram2dcontour", "x": [ 3.824, 4.5924, 4.588, 5.1992, 5.6358, 5.1376, 5.082, 5.6925, 5.6925, 6.384, 6.11, 5.64, 6.11, 5.875, 5.856, 6.792000000000001, 5.9532, 5.2185, 7.292999999999999, 6.375, 6.561, 7.167999999999999, 8.323, 7.1672, 7.0516, 7.8204, 10.03, 10.2565, 11.4884, 10.880999999999998, 10.6091, 10.5717, 11.1366, 11.1366, 12.4313, 11.9286, 11.73, 12.3808, 11.135, 12.8002, 11.9328, 12.5125 ], "xaxis": "x", "xbingroup": "x", "y": [ 2.432, 2.6316, 2.9415, 3.1234, 3.0502, 3.0368, 2.772, 3.555, 3.6675, 3.534, 3.4075, 3.525, 3.525, 3.525, 3.624, 3.624, 3.63, 3.626, 3.723, 3.825, 4.239, 4.144, 5.1373, 4.335, 4.335, 4.2042, 6.018, 6.3875, 7.7957, 6.864, 6.7408, 6.3666, 7.4934, 6.002999999999999, 7.3514, 7.1064, 7.225, 7.4624, 6.63, 6.8684, 7.2772, 7.4165 ], "yaxis": "y", "ybingroup": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Okoun
Height=%{x}
count=%{y}", "legendgroup": "Okoun", "marker": { "color": "#FFA15A" }, "name": "Okoun", "offsetgroup": "Okoun", "opacity": 0.5, "showlegend": false, "type": "histogram", "x": [ 3.824, 4.5924, 4.588, 5.1992, 5.6358, 5.1376, 5.082, 5.6925, 5.6925, 6.384, 6.11, 5.64, 6.11, 5.875, 5.856, 6.792000000000001, 5.9532, 5.2185, 7.292999999999999, 6.375, 6.561, 7.167999999999999, 8.323, 7.1672, 7.0516, 7.8204, 10.03, 10.2565, 11.4884, 10.880999999999998, 10.6091, 10.5717, 11.1366, 11.1366, 12.4313, 11.9286, 11.73, 12.3808, 11.135, 12.8002, 11.9328, 12.5125 ], "xaxis": "x3", "yaxis": "y3" }, { "alignmentgroup": "True", "bingroup": "y", "hovertemplate": "Species=Okoun
Width=%{y}
count=%{x}", "legendgroup": "Okoun", "marker": { "color": "#FFA15A" }, "name": "Okoun", "offsetgroup": "Okoun", "opacity": 0.5, "showlegend": false, "type": "histogram", "xaxis": "x2", "y": [ 2.432, 2.6316, 2.9415, 3.1234, 3.0502, 3.0368, 2.772, 3.555, 3.6675, 3.534, 3.4075, 3.525, 3.525, 3.525, 3.624, 3.624, 3.63, 3.626, 3.723, 3.825, 4.239, 4.144, 5.1373, 4.335, 4.335, 4.2042, 6.018, 6.3875, 7.7957, 6.864, 6.7408, 6.3666, 7.4934, 6.002999999999999, 7.3514, 7.1064, 7.225, 7.4624, 6.63, 6.8684, 7.2772, 7.4165 ], "yaxis": "y2" }, { "contours": { "coloring": "none" }, "hovertemplate": "Species=Štika
Height=%{x}
Width=%{y}
count=%{z}", "legendgroup": "Štika", "line": { "color": "#19d3f3" }, "name": "Štika", "showlegend": true, "type": "histogram2dcontour", "x": [ 5.568, 5.7078, 5.9364, 6.2884, 7.29, 6.396, 7.28, 6.825, 7.786, 6.96, 7.792000000000001, 7.68, 10.6863, 9.6, 9.6 ], "xaxis": "x", "xbingroup": "x", "y": [ 3.3756, 4.158, 4.3844, 4.0198, 4.5765, 3.977, 4.3225, 4.459, 5.1296, 4.896, 4.87, 5.376, 6.9849, 6.144, 6.144 ], "yaxis": "y", "ybingroup": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Štika
Height=%{x}
count=%{y}", "legendgroup": "Štika", "marker": { "color": "#19d3f3" }, "name": "Štika", "offsetgroup": "Štika", "opacity": 0.5, "showlegend": false, "type": "histogram", "x": [ 5.568, 5.7078, 5.9364, 6.2884, 7.29, 6.396, 7.28, 6.825, 7.786, 6.96, 7.792000000000001, 7.68, 10.6863, 9.6, 9.6 ], "xaxis": "x3", "yaxis": "y3" }, { "alignmentgroup": "True", "bingroup": "y", "hovertemplate": "Species=Štika
Width=%{y}
count=%{x}", "legendgroup": "Štika", "marker": { "color": "#19d3f3" }, "name": "Štika", "offsetgroup": "Štika", "opacity": 0.5, "showlegend": false, "type": "histogram", "xaxis": "x2", "y": [ 3.3756, 4.158, 4.3844, 4.0198, 4.5765, 3.977, 4.3225, 4.459, 5.1296, 4.896, 4.87, 5.376, 6.9849, 6.144, 6.144 ], "yaxis": "y2" }, { "contours": { "coloring": "none" }, "hovertemplate": "Species=Koruška
Height=%{x}
Width=%{y}
count=%{z}", "legendgroup": "Koruška", "line": { "color": "#FF6692" }, "name": "Koruška", "showlegend": true, "type": "histogram2dcontour", "x": [ 1.7388, 1.972, 1.7284, 2.196, 2.0832, 1.9782, 2.2139, 2.2139, 2.2044, 2.0904, 2.43, 2.277, 2.9322 ], "xaxis": "x", "xbingroup": "x", "y": [ 1.0476, 1.16, 1.1484, 1.38, 1.2772, 1.2852, 1.2838, 1.1659, 1.1484, 1.3936, 1.269, 1.2558, 1.8792 ], "yaxis": "y", "ybingroup": "y" }, { "alignmentgroup": "True", "bingroup": "x", "hovertemplate": "Species=Koruška
Height=%{x}
count=%{y}", "legendgroup": "Koruška", "marker": { "color": "#FF6692" }, "name": "Koruška", "offsetgroup": "Koruška", "opacity": 0.5, "showlegend": false, "type": "histogram", "x": [ 1.7388, 1.972, 1.7284, 2.196, 2.0832, 1.9782, 2.2139, 2.2139, 2.2044, 2.0904, 2.43, 2.277, 2.9322 ], "xaxis": "x3", "yaxis": "y3" }, { "alignmentgroup": "True", "bingroup": "y", "hovertemplate": "Species=Koruška
Width=%{y}
count=%{x}", "legendgroup": "Koruška", "marker": { "color": "#FF6692" }, "name": "Koruška", "offsetgroup": "Koruška", "opacity": 0.5, "showlegend": false, "type": "histogram", "xaxis": "x2", "y": [ 1.0476, 1.16, 1.1484, 1.38, 1.2772, 1.2852, 1.2838, 1.1659, 1.1484, 1.3936, 1.269, 1.2558, 1.8792 ], "yaxis": "y2" } ], "layout": { "barmode": "overlay", "legend": { "title": { "text": "Species" }, "tracegroupgap": 0 }, "margin": { "t": 60 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "xaxis": { "anchor": "y", "domain": [ 0, 0.7363 ], "title": { "text": "Height" } }, "xaxis2": { "anchor": "y2", "domain": [ 0.7413, 1 ], "matches": "x2", "showgrid": true, "showline": false, "showticklabels": false, "ticks": "" }, "xaxis3": { "anchor": "y3", "domain": [ 0, 0.7363 ], "matches": "x", "showgrid": true, "showticklabels": false }, "xaxis4": { "anchor": "y4", "domain": [ 0.7413, 1 ], "matches": "x2", "showgrid": true, "showline": false, "showticklabels": false, "ticks": "" }, "yaxis": { "anchor": "x", "domain": [ 0, 0.7326 ], "title": { "text": "Width" } }, "yaxis2": { "anchor": "x2", "domain": [ 0, 0.7326 ], "matches": "y", "showgrid": true, "showticklabels": false }, "yaxis3": { "anchor": "x3", "domain": [ 0.7426, 1 ], "matches": "y3", "showgrid": true, "showline": false, "showticklabels": false, "ticks": "" }, "yaxis4": { "anchor": "x4", "domain": [ 0.7426, 1 ], "matches": "y3", "showgrid": true, "showline": false, "showticklabels": false, "ticks": "" } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "px.density_contour(\n", " fish_data,\n", " color=\"Species\",\n", " x=\"Height\",\n", " y=\"Width\",\n", " marginal_x=\"histogram\",\n", " marginal_y=\"histogram\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Úkol:** Zkuste si zobrazit v grafech jiné veličiny (jiné sloupce) než Height a Width. Zkuste změnit typ marginálních grafů." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Co s tím dál?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Report pro šéfa a šéfovou\n", "\n", "Máme i kolegy, kteří (ještě) nepoužívají Python a přesto by ocenili, kdyby mohli místo statického reportu dostat report s takto krásnými a interaktivními vizualizacemi. Pro tento účel se hodí export notebooku do html pomocí `nbconvert`.\n", "\n", "V příkazovém řádku spustíme `nbconvert` pomocí příkazu `jupyter nbconvert`. Pro export do html pak přidáme `--to html`, nesmíme zapomenout zadat který notebook (tj. soubor) chceme vlastně konvertovat." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2391.46s - pydevd: Sending message related to process being replaced timed-out after 5 seconds\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[NbConvertApp] Converting notebook dashboardy-1.ipynb to html\n", "[NbConvertApp] Writing 4363870 bytes to dashboardy-1.html\n" ] } ], "source": [ "# Odkomentováním se spustí příkaz v příkazové řádce (díky vykřičníku)\n", "# Možná se soubor u tebe jmenuje jinak než dashboardy-1, v takovém použij aktuální jméno souboru\n", "!jupyter nbconvert dashboardy-1.ipynb --to html" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Můžeme také exportovat jen výstupy a \"utajit\" zdrojový kód pomocí `--no-input`:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2445.54s - pydevd: Sending message related to process being replaced timed-out after 5 seconds\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[NbConvertApp] Converting notebook dashboardy-1.ipynb to html\n", "[NbConvertApp] Writing 4341390 bytes to dashboardy-1.html\n" ] } ], "source": [ "!jupyter nbconvert dashboardy-1.ipynb --to html --no-input" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Analýza nových dat\n", "\n", "Všem se naše vizualizace líbily, a jelikož je potřeba analyzovat další data, dostali jsme to za úkol my. Tentokrát se nejedná o ryby, ale o tučňáky." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Úkol:** Vyber si z grafů ten, který se ti nejvíc líbí, a místo rybích dat použij tučňáky." ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "penguins = pd.read_csv(\"../data/penguins_size_nona.csv\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Vytváříme aplikaci\n", "\n", "Z naší práce v notebooku vykrystalizoval velice častý vzor: Podobné vizualizace a analýzy, v nichž se mění data a několik klíčových parametrů. Příležitost vytvořit aplikaci, která toto umožní nám a okruhu poučených uživatelů." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pojďme si nadefinovat naší jednoduchou aplikaci:\n", "1. Načíst data z csv souboru.\n", "2. Vykreslit scatter matrix, kde budu moct zvolit dimenze, sloupec pro barvu a průhlednost.\n", "3. Pro vybraný sloupec zobrazit distribuci vybraného sloupce pomocí histogramu, box plotu nebo violin plotu." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Příprava v notebooku\n", "\n", "Pojďme to nejprve načrtnout tady v notebooku. Jako první si připravíme uživatelské vstupy." ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "# vstup 1: výběr datové sady\n", "data_file_path = \"../data/penguins_size_nona.csv\"\n", "# vstup 2: výběr parametrů scatter matrix\n", "dimensions = ['culmen_length_mm', 'culmen_depth_mm', 'flipper_length_mm', 'body_mass_g']\n", "color = \"sex\"\n", "opacity = 0.5\n", "# výběr sloupce pro zobrazení rozdělení dat\n", "interesting_column = \"body_mass_g\"\n", "# výběr funkce pro zobrazení rozdělovací funkce\n", "dist_plot = px.violin\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A tohle už je pak naše aplikace: Použili jsme stejné funkce a parametry jako na začátku práce s plotly, jen jsme je parametrizovali pomocí vstupů z předchozího bloku." ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "# načtení dat\n", "data = pd.read_csv(data_file_path)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "dimensions": [ { "axis": { "matches": true }, "label": "culmen_length_mm", "values": [ 39.1, 39.3, 39.2, 38.6, 34.6, 42.5, 46, 37.7, 38.2, 38.8, 40.6, 40.5, 37.2, 40.9, 39.2, 38.8, 39.8, 40.8, 44.1, 39.6, 41.1, 42.3, 40.1, 42, 41.4, 40.6, 37.6, 41.3, 41.1, 41.6, 41.1, 41.8, 39.7, 45.8, 42.8, 37.2, 42.1, 42.9, 35.1, 41.3, 36.3, 38.3, 41.1, 39.6, 40.8, 40.3, 43.2, 41, 37.8, 39.7, 38.2, 43.2, 45.6, 42.2, 42.7, 37.3, 41.1, 37.7, 41.4, 40.6, 41.5, 44.1, 43.1, 37.5, 41.1, 40.2, 39.7, 40.6, 40.7, 39, 39.2, 37.8, 41.5, 50, 51.3, 52.7, 51.3, 51.3, 51.7, 52, 50.5, 50.3, 49.2, 48.5, 50.6, 52, 49.5, 52.8, 54.2, 51, 49.7, 52, 53.5, 49, 50.9, 50.8, 49, 51.5, 51.4, 50.7, 52.2, 49.3, 50.2, 51.9, 55.8, 49.6, 50.8, 50, 50, 47.6, 46.7, 46.8, 49, 48.4, 49.3, 49.2, 48.7, 50.2, 46.3, 46.1, 47.8, 50, 47.3, 59.6, 48.4, 44.4, 48.7, 49.6, 49.6, 50.5, 50.5, 45.2, 48.5, 50.1, 45, 45.5, 50.4, 46.2, 54.3, 49.8, 49.5, 50.7, 46.4, 48.2, 48.6, 51.1, 45.2, 52.5, 50, 50.8, 51.3, 52.1, 52.2, 49.5, 50.8, 49.4, 51.1, 55.9, 49.1, 46.8, 53.4, 48.1, 49.8, 51.5, 55.1, 48.8, 50.4, 49.9 ] }, { "axis": { "matches": true }, "label": "culmen_depth_mm", "values": [ 18.7, 20.6, 19.6, 21.2, 21.1, 20.7, 21.5, 18.7, 18.1, 17.2, 18.6, 18.9, 18.1, 18.9, 21.1, 20, 19.1, 18.4, 19.7, 18.8, 19, 21.2, 18.9, 19.5, 18.6, 18.8, 19.1, 21.1, 18.2, 18, 19.1, 19.4, 18.4, 18.9, 18.5, 19.4, 19.1, 17.6, 19.4, 20.3, 19.5, 19.2, 18.1, 18.1, 18.9, 18.5, 18.5, 20, 20, 18.9, 20, 19, 20.3, 19.5, 18.3, 20.5, 18.6, 19.8, 18.5, 19, 18.3, 18, 19.2, 18.5, 17.5, 20.1, 17.9, 17.2, 17, 18.7, 18.6, 18.1, 18.5, 19.5, 19.2, 19.8, 18.2, 19.9, 20.3, 18.1, 19.6, 20, 18.2, 17.5, 19.4, 19, 19, 20, 20.8, 18.8, 18.6, 20.7, 19.9, 19.5, 19.1, 18.5, 19.6, 18.7, 19, 19.7, 18.8, 19.9, 18.8, 19.5, 19.8, 18.2, 19, 16.3, 15.2, 14.5, 15.3, 15.4, 16.1, 14.6, 15.7, 15.2, 15.1, 14.3, 15.8, 15.1, 15, 15.3, 15.3, 17, 16.3, 17.3, 15.7, 16, 15, 15.9, 15.9, 15.8, 14.1, 15, 15.4, 15, 15.3, 14.9, 15.7, 16.8, 16.2, 15, 15.6, 15.6, 16, 16.3, 16.4, 15.6, 15.9, 17.3, 14.2, 17, 17.1, 16.1, 15.7, 15.8, 16.5, 17, 15, 16.1, 15.8, 15.1, 15.9, 16.3, 16, 16.2, 15.7, 16.1 ] }, { "axis": { "matches": true }, "label": "flipper_length_mm", "values": [ 181, 190, 195, 191, 198, 197, 194, 180, 185, 180, 183, 180, 178, 184, 196, 190, 184, 195, 196, 190, 182, 191, 188, 200, 191, 193, 194, 195, 192, 192, 188, 198, 190, 197, 195, 184, 195, 196, 193, 194, 190, 189, 205, 186, 208, 196, 192, 203, 190, 184, 190, 197, 191, 197, 196, 199, 189, 198, 202, 199, 195, 210, 197, 199, 190, 200, 193, 187, 190, 185, 190, 193, 201, 196, 193, 197, 197, 198, 194, 201, 201, 197, 195, 191, 193, 197, 200, 205, 201, 203, 195, 210, 205, 210, 196, 201, 212, 187, 201, 203, 197, 203, 202, 206, 207, 193, 210, 230, 218, 215, 219, 215, 216, 213, 217, 221, 222, 218, 215, 215, 215, 220, 222, 230, 220, 219, 208, 225, 216, 222, 225, 215, 220, 225, 220, 220, 224, 221, 231, 230, 229, 223, 221, 221, 230, 220, 223, 221, 224, 228, 218, 230, 228, 224, 226, 216, 225, 228, 228, 215, 219, 209, 229, 230, 230, 222, 222, 213 ] }, { "axis": { "matches": true }, "label": "body_mass_g", "values": [ 3750, 3650, 4675, 3800, 4400, 4500, 4200, 3600, 3950, 3800, 3550, 3950, 3900, 3900, 4150, 3950, 4650, 3900, 4400, 4600, 3425, 4150, 4300, 4050, 3700, 3800, 3750, 4400, 4050, 3950, 4100, 4450, 3900, 4150, 4250, 3900, 4000, 4700, 4200, 3550, 3800, 3950, 4300, 4450, 4300, 4350, 4100, 4725, 4250, 3550, 3900, 4775, 4600, 4275, 4075, 3775, 3325, 3500, 3875, 4000, 4300, 4000, 3500, 4475, 3900, 3975, 4250, 3475, 3725, 3650, 4250, 3750, 4000, 3900, 3650, 3725, 3750, 3700, 3775, 4050, 4050, 3300, 4400, 3400, 3800, 4150, 3800, 4550, 4300, 4100, 3600, 4800, 4500, 3950, 3550, 4450, 4300, 3250, 3950, 4050, 3450, 4050, 3800, 3950, 4000, 3775, 4100, 5700, 5700, 5400, 5200, 5150, 5550, 5850, 5850, 6300, 5350, 5700, 5050, 5100, 5650, 5550, 5250, 6050, 5400, 5250, 5350, 5700, 4750, 5550, 5400, 5300, 5300, 5000, 5050, 5000, 5550, 5300, 5650, 5700, 5800, 5550, 5000, 5100, 5800, 6000, 5950, 5450, 5350, 5600, 5300, 5550, 5400, 5650, 5200, 4925, 5250, 5600, 5500, 5500, 5500, 5500, 5950, 5500, 5850, 6000, 5750, 5400 ] } ], "hovertemplate": "sex=MALE
%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "MALE", "marker": { "color": "#636efa", "opacity": 0.5, "symbol": "circle" }, "name": "MALE", "showlegend": true, "type": "splom" }, { "dimensions": [ { "axis": { "matches": true }, "label": "culmen_length_mm", "values": [ 39.5, 40.3, 36.7, 38.9, 41.1, 36.6, 38.7, 34.4, 37.8, 35.9, 35.3, 40.5, 37.9, 39.5, 39.5, 36.4, 42.2, 37.6, 36.5, 36, 37, 36, 39.6, 35, 34.5, 39, 36.5, 35.7, 37.6, 36.4, 35.5, 35.9, 33.5, 39.6, 35.5, 40.9, 36.2, 34.6, 36.7, 37.3, 36.9, 38.9, 35.7, 34, 36.2, 38.1, 33.1, 35, 37.7, 37.9, 38.6, 38.1, 38.1, 39.7, 39.6, 38.6, 35.7, 36.2, 40.2, 35.2, 38.8, 39, 38.5, 36.8, 38.1, 35.6, 37, 40.2, 32.1, 37.3, 36.6, 36, 36, 46.5, 45.4, 45.2, 46.1, 46, 46.6, 47, 45.9, 58, 46.4, 42.4, 43.2, 46.7, 50.5, 46.4, 40.9, 42.5, 47.5, 47.6, 46.9, 46.2, 45.5, 50.9, 50.1, 49.8, 48.1, 45.7, 42.5, 45.2, 45.6, 46.8, 45.7, 43.5, 50.2, 46.1, 48.7, 46.5, 45.4, 43.3, 40.9, 45.5, 45.8, 42, 46.2, 45.1, 46.5, 42.9, 48.2, 42.8, 45.1, 49.1, 42.6, 44, 42.7, 45.3, 43.6, 45.5, 44.9, 46.6, 45.1, 46.5, 43.8, 43.2, 45.3, 45.7, 45.8, 43.5, 47.7, 46.5, 46.4, 47.5, 45.2, 49.1, 47.4, 44.9, 43.4, 47.5, 47.5, 45.5, 44.5, 46.9, 48.4, 48.5, 47.2, 41.7, 43.3, 50.5, 43.5, 46.2, 47.2, 46.8, 45.2 ] }, { "axis": { "matches": true }, "label": "culmen_depth_mm", "values": [ 17.4, 18, 19.3, 17.8, 17.6, 17.8, 19, 18.4, 18.3, 19.2, 18.9, 17.9, 18.6, 16.7, 17.8, 17, 18.5, 19.3, 18, 18.5, 16.9, 17.9, 17.7, 17.9, 18.1, 17.5, 16.6, 16.9, 17, 17.1, 16.2, 16.6, 19, 17.2, 17.5, 16.8, 16.1, 17.2, 18.8, 17.8, 18.6, 18.8, 18, 17.1, 17.3, 18.6, 16.1, 17.9, 16, 18.6, 17.2, 17, 16.5, 17.7, 20.7, 17, 17, 17.2, 17, 15.9, 17.6, 17.1, 17.9, 18.5, 17.6, 17.5, 16.5, 17.1, 15.5, 16.8, 18.4, 17.8, 17.1, 17.9, 18.7, 17.8, 18.2, 18.9, 17.8, 17.3, 17.1, 17.8, 18.6, 17.3, 16.6, 17.9, 18.4, 17.8, 16.6, 16.7, 16.8, 18.3, 16.6, 17.5, 17, 17.9, 17.9, 17.3, 16.4, 17.3, 17.3, 16.6, 19.4, 16.5, 17, 18.1, 18.7, 13.2, 14.1, 13.5, 14.6, 13.4, 13.7, 13.7, 14.6, 13.5, 14.5, 14.5, 14.5, 13.1, 14.3, 14.2, 14.5, 14.8, 13.7, 13.6, 13.7, 13.7, 13.9, 13.9, 13.3, 14.2, 14.4, 14.4, 13.9, 14.5, 13.8, 13.9, 14.2, 14.2, 15, 14.8, 15, 14.2, 13.8, 14.5, 14.6, 13.8, 14.4, 14, 15, 14.5, 14.7, 14.6, 14.4, 15, 15.5, 14.7, 14, 15.2, 15.2, 14.1, 13.7, 14.3, 14.8 ] }, { "axis": { "matches": true }, "label": "flipper_length_mm", "values": [ 186, 195, 193, 181, 182, 185, 195, 184, 174, 189, 187, 187, 172, 178, 188, 195, 180, 181, 182, 186, 185, 190, 186, 190, 187, 186, 181, 185, 185, 184, 195, 190, 190, 196, 190, 191, 187, 189, 187, 191, 189, 190, 202, 185, 187, 190, 178, 192, 183, 193, 199, 181, 198, 193, 191, 188, 189, 187, 176, 186, 191, 191, 190, 193, 187, 191, 185, 193, 188, 192, 184, 195, 187, 192, 188, 198, 178, 195, 193, 185, 190, 181, 190, 181, 187, 195, 200, 191, 187, 187, 199, 195, 192, 187, 196, 196, 190, 198, 199, 193, 187, 191, 194, 189, 195, 202, 198, 211, 210, 210, 211, 209, 214, 214, 210, 210, 209, 215, 213, 215, 210, 209, 207, 220, 213, 208, 208, 210, 217, 210, 213, 210, 210, 217, 208, 208, 208, 214, 219, 220, 216, 217, 216, 209, 215, 212, 212, 212, 218, 212, 218, 212, 214, 222, 203, 219, 215, 210, 208, 216, 213, 217, 214, 215, 212 ] }, { "axis": { "matches": true }, "label": "body_mass_g", "values": [ 3800, 3250, 3450, 3625, 3200, 3700, 3450, 3325, 3400, 3800, 3800, 3200, 3150, 3250, 3300, 3325, 3550, 3300, 3150, 3100, 3000, 3450, 3500, 3450, 2900, 3550, 2850, 3150, 3600, 2850, 3350, 3050, 3600, 3550, 3700, 3700, 3550, 3200, 3800, 3350, 3500, 3600, 3550, 3400, 3300, 3700, 2900, 3725, 3075, 2925, 3750, 3175, 3825, 3200, 3900, 2900, 3350, 3150, 3450, 3050, 3275, 3050, 3325, 3500, 3425, 3175, 3400, 3400, 3050, 3000, 3475, 3450, 3700, 3500, 3525, 3950, 3250, 4150, 3800, 3700, 3575, 3700, 3450, 3600, 2900, 3300, 3400, 3700, 3200, 3350, 3900, 3850, 2700, 3650, 3500, 3675, 3400, 3675, 3325, 3600, 3350, 3250, 3525, 3650, 3650, 3400, 3775, 4500, 4450, 4550, 4800, 4400, 4650, 4650, 4200, 4150, 4800, 5000, 4400, 5000, 4600, 4700, 5050, 5150, 4950, 4350, 3950, 4300, 4900, 4200, 5100, 4850, 4400, 4900, 4300, 4450, 4200, 4400, 4700, 4700, 4750, 5200, 4700, 4600, 4750, 4625, 4725, 4750, 4600, 4875, 4950, 4750, 4850, 4875, 4625, 4850, 4975, 4700, 4575, 5000, 4650, 4375, 4925, 4850, 5200 ] } ], "hovertemplate": "sex=FEMALE
%{xaxis.title.text}=%{x}
%{yaxis.title.text}=%{y}", "legendgroup": "FEMALE", "marker": { "color": "#EF553B", "opacity": 0.5, "symbol": "circle" }, "name": "FEMALE", "showlegend": true, "type": "splom" } ], "layout": { "dragmode": "select", "legend": { "title": { "text": "sex" }, "tracegroupgap": 0 }, "margin": { "t": 60 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# scatter matric plat\n", "px.scatter_matrix(data, dimensions=dimensions, color=color, opacity=opacity)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "alignmentgroup": "True", "box": { "visible": false }, "hovertemplate": "sex=MALE
body_mass_g=%{x}", "legendgroup": "MALE", "marker": { "color": "#636efa" }, "name": "MALE", "offsetgroup": "MALE", "orientation": "h", "scalegroup": "True", "showlegend": true, "type": "violin", "x": [ 3750, 3650, 4675, 3800, 4400, 4500, 4200, 3600, 3950, 3800, 3550, 3950, 3900, 3900, 4150, 3950, 4650, 3900, 4400, 4600, 3425, 4150, 4300, 4050, 3700, 3800, 3750, 4400, 4050, 3950, 4100, 4450, 3900, 4150, 4250, 3900, 4000, 4700, 4200, 3550, 3800, 3950, 4300, 4450, 4300, 4350, 4100, 4725, 4250, 3550, 3900, 4775, 4600, 4275, 4075, 3775, 3325, 3500, 3875, 4000, 4300, 4000, 3500, 4475, 3900, 3975, 4250, 3475, 3725, 3650, 4250, 3750, 4000, 3900, 3650, 3725, 3750, 3700, 3775, 4050, 4050, 3300, 4400, 3400, 3800, 4150, 3800, 4550, 4300, 4100, 3600, 4800, 4500, 3950, 3550, 4450, 4300, 3250, 3950, 4050, 3450, 4050, 3800, 3950, 4000, 3775, 4100, 5700, 5700, 5400, 5200, 5150, 5550, 5850, 5850, 6300, 5350, 5700, 5050, 5100, 5650, 5550, 5250, 6050, 5400, 5250, 5350, 5700, 4750, 5550, 5400, 5300, 5300, 5000, 5050, 5000, 5550, 5300, 5650, 5700, 5800, 5550, 5000, 5100, 5800, 6000, 5950, 5450, 5350, 5600, 5300, 5550, 5400, 5650, 5200, 4925, 5250, 5600, 5500, 5500, 5500, 5500, 5950, 5500, 5850, 6000, 5750, 5400 ], "x0": " ", "xaxis": "x", "y0": " ", "yaxis": "y" }, { "alignmentgroup": "True", "box": { "visible": false }, "hovertemplate": "sex=FEMALE
body_mass_g=%{x}", "legendgroup": "FEMALE", "marker": { "color": "#EF553B" }, "name": "FEMALE", "offsetgroup": "FEMALE", "orientation": "h", "scalegroup": "True", "showlegend": true, "type": "violin", "x": [ 3800, 3250, 3450, 3625, 3200, 3700, 3450, 3325, 3400, 3800, 3800, 3200, 3150, 3250, 3300, 3325, 3550, 3300, 3150, 3100, 3000, 3450, 3500, 3450, 2900, 3550, 2850, 3150, 3600, 2850, 3350, 3050, 3600, 3550, 3700, 3700, 3550, 3200, 3800, 3350, 3500, 3600, 3550, 3400, 3300, 3700, 2900, 3725, 3075, 2925, 3750, 3175, 3825, 3200, 3900, 2900, 3350, 3150, 3450, 3050, 3275, 3050, 3325, 3500, 3425, 3175, 3400, 3400, 3050, 3000, 3475, 3450, 3700, 3500, 3525, 3950, 3250, 4150, 3800, 3700, 3575, 3700, 3450, 3600, 2900, 3300, 3400, 3700, 3200, 3350, 3900, 3850, 2700, 3650, 3500, 3675, 3400, 3675, 3325, 3600, 3350, 3250, 3525, 3650, 3650, 3400, 3775, 4500, 4450, 4550, 4800, 4400, 4650, 4650, 4200, 4150, 4800, 5000, 4400, 5000, 4600, 4700, 5050, 5150, 4950, 4350, 3950, 4300, 4900, 4200, 5100, 4850, 4400, 4900, 4300, 4450, 4200, 4400, 4700, 4700, 4750, 5200, 4700, 4600, 4750, 4625, 4725, 4750, 4600, 4875, 4950, 4750, 4850, 4875, 4625, 4850, 4975, 4700, 4575, 5000, 4650, 4375, 4925, 4850, 5200 ], "x0": " ", "xaxis": "x", "y0": " ", "yaxis": "y" } ], "layout": { "legend": { "title": { "text": "sex" }, "tracegroupgap": 0 }, "margin": { "t": 60 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "violinmode": "group", "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "body_mass_g" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ] } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# zobrazení rozdělovací funkce\n", "dist_plot(data, x=interesting_column, color=color)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A teď z toho pojďme udělat interaktivní webovou aplikaci! To nebudeme dělat přímo tady v notebooku, ale v \"obyčejném\" .py souboru s Python kódem.\n", "\n", "Aplikaci máme připravenou v souboru `app.py`, tady v notebooku si soubor můžeme prohlédnout:" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "%load ../app.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Základem je, že uživatelské vstupy jsme předělali z podoby `proměnná = hodnota` do podoby `proměnná = st.vhodný_widget(...)`. Toto je způsob vytváření streamlit aplikace: \n", "* Aplikaci píšeme v podstatě jako lineární skript (zdrojový kód samozřejmě můžeme strukturovat do funkcí / modulů / tříd dle vlastního uvážení, streamlit ale bude aplikaci vždy spouštět krok po kroku jako ten skript).\n", "* Uživatelské vstupy načítáme z návratové hodnoty funkcí `st.nějaký_widget`, Streamlit se postará o to, aby widget správně fungoval a návratová hodnota byla vždy ta aktuální.\n", "* Prvky aplikace (výstupy) zobrazíme uživateli pomocí `st.write`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Widgets - pomocné \"věcičky\":* V uživatelských grafických rozhraních (GUI) se používají *widgety*: nástroje na vybrání možností, hodnoty proměnné, zadání textu nebo datumu apod.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Spuštění\n", "\n", "Streamlit ještě nejspíš nemáš nainstalovaný. Instaluje se běžným způsobem přes pip:\n", "\n", " pip install streamlit==1.40.0\n", " \n", "případně pokud používáš conda\n", "\n", " conda install -c conda-forge streamlit=1.40.0\n", "\n", "Na svém počítači si pak aplikaci spustíš příkazem `streamlit run` s názvem souboru s aplikací. V našem případě tedy\n", "\n", " streamlit run app.py\n", " \n", "Pokud je vše v pořádku, zobrazí se něco takovéhoto:\n", "\n", "```\n", " You can now view your Streamlit app in your browser.\n", "\n", " Network URL: http://192.168.2.103:8800\n", " External URL: http://85.207.123.46:8800\n", "```\n", "\n", "Dle instrukcí otevři odkaz (ten první) v prohlížeči. Je velká pravděpodobnost, že se objeví naše právě vytvořená aplikace na vizualizaci dat." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Publikujeme na internet\n", "\n", "V principu bychom mohli spustit aplikaci u sebe na počítači tak, aby ji mohli používat i další uživatelé. Na vnitřní síti (domácí, pracovní) by to bylo snadné (i když na pracovní síti a pracovním počítači by tomu mohla bránit bezpečnostní nastavení), přístup z vnějšího internetu by už byl komplikovanější.\n", "\n", "Naštěstí nejsme v podobné situaci sami :) Takže existují více či méně složité a sofistikované způsoby, jak aplikaci spustit na nějakém serveru (v cloudu) a zpřístupnit z internetu. My si ukážeme, jak to funguje na [Streamlit Cloud](https://streamlit.io/cloud), což je možná nejjednodušší způsob publikace Streamlit aplikace z GitHub repozitáře. Oproti obecnějším službám má pochopitelně méně možností a funguje pouze pro Streamlit.\n", "\n", "Pro sofistikovanější aplikace je pak možné použít některou z PaaS (Platform as a Service) služeb typu Render, Heroku, AWS Elastic Beanstalk, Google App Engine, Digital Ocean Apps. Některé z těchto služeb mají i zajímavé bezplatné plány nebo kredit pro nové uživatele." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Registrace na Streamlit Cloud\n", "\n", "Než začneme, je potřeba:\n", "1. Github účet a Git klient: viz [README - Příprava](../README.md#příprava).\n", "2. Použij svůj GitHub účet pro registraci na Streamlit Cloud: https://share.streamlit.io/signup\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Specifikace prostředí\n", "\n", "Aby bylo jasné, jaké Python balíčky jsou potřeba pro naši aplikaci a tím si ji kdokoli mohl spustit, vytvoříme soubor [`requirements.txt`](https://pip.pypa.io/en/stable/reference/requirements-file-format/). Ten může použít buď lidský uživatel nebo platforma typu Streamlit Cloud.\n", "\n", "V souboru `requirements.txt` potřebujeme mít (alespoň) základní balíčky pro spuštění aplikace:\n", "```\n", "pandas==2.2.3\n", "streamlit==1.40.0\n", "plotly==5.24.1\n", "```\n", "* Je lepší specifikovat konkrétní verzi, protože novější nebo starší verze nemusí být kompatibilní.\n", "* Ideální je specifikovat všechny závislosti včetně \"tranzitivních\", tj. závislosti závislostí (... závislostí ...). Pro zjednodušení tohoto úkolu existují pomocné nástroje, např. [uv](https://github.com/astral-sh/uv) nebo [Poetry](https://python-poetry.org). My si zatím vystačíme s jednoduchým `requirements.txt` souborem.\n", "\n", "Tento soubor umí použít `pip`: Pro instalaci balíčků stačí spustit\n", "```\n", "python -m pip install -r requirements.txt\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Publikace na GitHub\n", "\n", "#### 1. Vytvoř nový GitHub projekt:\n", "\n", "* Vytvoř nový projekt na [github.com](https://github.com)\n", "\n", "\n", "\n", "* Vyber vhodné jméno.\n", "* Můžeš použít soukromý i veřejný projekt.\n", "* Přidej Python `.gitignore` soubor z nabídky.\n", "* Můžeš přidat i README soubor.\n", "\n", "#### 2. Naklonuj projekt k sobě na počítač\n", "\n", "Po vytvoření projektu se objeví instrukce na naklonování (nahrání) projektu na tvůj počítač. Použij například `gh` v příkazové řádce.\n", "\n", "```\n", "gh repo clone uživatelské-jméno/název-repozitáře\n", "```\n", "\n", "#### 3. Přidej soubory s aplikací\n", "\n", "Do projektu přidej soubory s aplikací, tedy `app.py` a `requirements.txt`. Poté je přidej do Gitu a udělej commit:\n", "\n", "```\n", "git add app.py requirements.txt\n", "git commit -m \"První verze aplikace\"\n", "```\n", "\n", "#### 4. Nahraj na GitHub\n", "\n", "Nahraj změny na GitHub pomocí `git push`.\n", "```\n", "git push\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Go-live\n", "\n", "Jakmile máme projekt na GitHubu, je snadné ho publikovat na Streamlit Cloud. Protože jsme pro registraci na Streamlit Cloud použili náš GitHub účet, má Streamlit přístup k našim repozitářům. (Pokud ne, můžeme přístup udělit dodatečně.)\n", "\n", "Pro vytvoření nové aplikace klikni na „New app“, poté vyplň jaký repozitář se má použít a jméno souboru s aplikací - pro nás to je `app.py`.\n", "\n", "Vyber také v sekci Advanced settings verzi Pythonu 3.11.\n", "\n", "\n", "\n", "Podrobný návod najdeš na https://docs.streamlit.io/streamlit-cloud/get-started/deploy-an-app.\n", "\n", "Za chvilku by tvoje aplikace měla být dostupná na internetu 🎉\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Úkol 1:** Pošli odkaz na tvou běžící aplikaci :)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Úkol 2:** Pomocí `st.title` změň titulek (název) aplikace. Vyzkoušej u sebe lokálně, pak změnu \"commituj\" do gitu a nahraj (`git push`) na GitHub. Tvoje změna by se měla (s drobným zpožděním) projevit i v online verzi." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Úkol 3:** Přidej do aplikace možnost schovat část s parametry scatter matrix. Použij `st.expander`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Úkol 4:** Přidej do aplikace možnost filtrovat data podle rozsahu hodnot. Konkrétně:\n", "* K ovládacím prvkům přidej výběr sloupce, který se má filtrovat.\n", "* Použij `st.slider` s dvojitým posuvníkem (range slider) k výběru rozsahu hodnot.\n", "* Všechny následující grafy by měly zobrazovat pouze data v tomto rozsahu." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.6" }, "vscode": { "interpreter": { "hash": "27fe3e3a9c4db7a524cc429dec4404166da744bafecc0eb690814f7ed01a5156" } } }, "nbformat": 4, "nbformat_minor": 4 }