{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "kz78I-lfEq7N", "outputId": "9c8c2d77-469a-4433-aa87-0e4e479607b9" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Figure({\n", " 'data': [{'hovertemplate': 'x=%{x}
y=%{y}',\n", " 'legendgroup': '',\n", " 'line': {'color': '#636efa', 'dash': 'solid'},\n", " 'marker': {'symbol': 'circle'},\n", " 'mode': 'lines',\n", " 'name': '',\n", " 'orientation': 'v',\n", " 'showlegend': False,\n", " 'type': 'scatter',\n", " 'x': array([1, 2]),\n", " 'xaxis': 'x',\n", " 'y': array([3, 4]),\n", " 'yaxis': 'y'}],\n", " 'layout': {'legend': {'tracegroupgap': 0},\n", " 'margin': {'t': 60},\n", " 'template': '...',\n", " 'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'x'}},\n", " 'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'y'}}}\n", "})\n" ] } ], "source": [ "import plotly.express as px\n", "\n", "fig = px.line(x=[1, 2], y=[3, 4])\n", "\n", "print(fig)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "7I5B5-ngFU6r", "outputId": "4e2308b8-7f97-4d80-f25b-f956eed8f80f" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.iris()\n", "\n", "fig = px.line(df, y=\"sepal_width\",)\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "XDvLG_h0FU4v", "outputId": "b45df9ef-110f-49a9-d376-578f22ab6816" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.iris()\n", "\n", "fig = px.line(df, y=\"sepal_width\", line_group='species')\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "Ua0O7nyWFU2Y", "outputId": "5b69e0c6-138c-4ed4-9db5-3b3d9beb0dfa" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.iris()\n", "\n", "fig = px.line(df, y=\"sepal_width\", line_dash='species',\n", " color='species')\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "Ac_eKzHDFU0U", "outputId": "73d21373-df29-47f0-e016-70ce5cd67475" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.bar(df, x='day', y=\"total_bill\")\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "XeqhxjR7FUxy", "outputId": "e8ab274d-250b-4eea-b57c-9df0f619a411" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.bar(df, x='day', y=\"total_bill\", color='sex',\n", " facet_row='time', facet_col='sex')\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "N87zrhLaFUuy", "outputId": "5b02a38e-a2fd-453c-86c4-942157d779f9" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.scatter(df, x='total_bill', y=\"tip\")\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "qTwsg4pnFUsc", "outputId": "448d0770-e0f7-4011-b6e8-bd8a183e4c5a" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.scatter(df, x='total_bill', y=\"tip\", color='time',\n", " symbol='sex', size='size', facet_row='day',\n", " facet_col='time')\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "Nx5R4sdXFUqV", "outputId": "57f47a1a-4c29-4662-a9e1-7d5eedd6cd42" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.histogram(df, x=\"total_bill\")\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "ErDl4z2rFUn9", "outputId": "bd56103e-6fb4-43f0-de06-cdd73ad291bc" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "\n", "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.histogram(df, x=\"total_bill\", color='sex',\n", " nbins=50, histnorm='percent',\n", " barmode='overlay')\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "WOFUsLNbFUln", "outputId": "d2fda47b-6301-4b54-b700-dde4faa57625" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "\n", "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.pie(df, values=\"total_bill\", names=\"day\")\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "PpP93EIHFUjV", "outputId": "aed7c2f1-2568-440a-ceaa-b21ac2a3235a" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "\n", "\n", "\n", "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.pie(df, values=\"total_bill\", names=\"day\",\n", " color_discrete_sequence=px.colors.sequential.RdBu,\n", " opacity=0.7, hole=0.5)\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "01Anlv3UFUgk", "outputId": "f6d793a0-e83b-4b19-a94d-1d5002da6c19" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.box(df, x=\"day\", y=\"tip\")\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "wcKYAEFQF9qN", "outputId": "7807c918-cd19-47ab-bf7a-682564ccb6c3" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.box(df, x=\"day\", y=\"tip\", color='sex',\n", " facet_row='time', boxmode='group',\n", " notched=True)\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "QQU5O54zF9lV", "outputId": "297f82fb-3ba1-4611-ed32-25eb105448b9" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.violin(df, x=\"day\", y=\"tip\")\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "uKcT0td8F9is", "outputId": "6ccbf6db-1094-4d33-f06f-dc2537f1a2b6" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.violin(df, x=\"day\", y=\"tip\", color='sex',\n", " facet_row='time', box=True)\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "w7uteoJWGIj0", "outputId": "553751a6-16aa-47f0-868a-3a158e0f5570" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.scatter_3d(df, x=\"total_bill\", y=\"sex\", z=\"tip\")\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "8vESsJB1GKB4", "outputId": "8ac6a2ea-fdcd-4258-919a-fa4a91f2db9e" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.express as px\n", "\n", "df = px.data.tips()\n", "\n", "fig = px.scatter_3d(df, x=\"total_bill\", y=\"sex\", z=\"tip\", color='day',\n", " size='total_bill', symbol='time')\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "1ysiKjcVGJ_0", "outputId": "87de75cd-73bf-4eee-db7b-b78f36dd404c" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.graph_objects as px\n", "import numpy as np\n", "import pandas as pd\n", "\n", "df = pd.read_csv('/content/tips.csv')\n", "\n", "plot = px.Figure(data=[px.Scatter(\n", " x=df['day'],\n", " y=df['tip'],\n", " mode='markers',)\n", "])\n", "\n", "plot.update_layout(\n", " updatemenus=[\n", " dict(buttons=list([\n", " dict(\n", " args=[\"type\", \"scatter\"],\n", " label=\"Scatter Plot\",\n", " method=\"restyle\"\n", " ),\n", " dict(\n", " args=[\"type\", \"bar\"],\n", " label=\"Bar Chart\",\n", " method=\"restyle\"\n", " )\n", " ]),\n", " direction=\"down\",\n", " ),\n", " ]\n", ")\n", "\n", "plot.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "zpYJXJtIGJ9D", "outputId": "7d4120ca-70d5-4b5d-abcb-5c6b2cd64d84" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.graph_objects as px\n", "import pandas as pd\n", "\n", "df = pd.read_csv('/content/tips.csv')\n", "\n", "plot = px.Figure(data=[px.Scatter(\n", " x=df['day'],\n", " y=df['tip'],\n", " mode='markers',)\n", "])\n", "\n", "plot.update_layout(\n", " updatemenus=[\n", " dict(\n", " type=\"buttons\",\n", " direction=\"left\",\n", " buttons=list([\n", " dict(\n", " args=[\"type\", \"scatter\"],\n", " label=\"Scatter Plot\",\n", " method=\"restyle\"\n", " ),\n", " dict(\n", " args=[\"type\", \"bar\"],\n", " label=\"Bar Chart\",\n", " method=\"restyle\"\n", " )\n", " ]),\n", " ),\n", " ]\n", ")\n", "\n", "plot.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 542 }, "id": "9Z2Os4ujGPoq", "outputId": "50d33395-e4dd-45c3-daf0-fc504a4490d6" }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly.graph_objects as px\n", "import plotly.express as go\n", "import numpy as np\n", "\n", "df = go.data.tips()\n", "\n", "x = df['total_bill']\n", "y = df['tip']\n", "\n", "plot = px.Figure(data=[px.Scatter(\n", " x=x,\n", " y=y,\n", " mode='markers',)\n", "])\n", "\n", "plot.update_layout(\n", " xaxis=dict(\n", " rangeselector=dict(\n", " buttons=list([\n", " dict(count=1,\n", " step=\"day\",\n", " stepmode=\"backward\"),\n", " ])\n", " ),\n", " rangeslider=dict(\n", " visible=True\n", " ),\n", " )\n", ")\n", "\n", "plot.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "zXzw9NPPGPmv" }, "outputs": [], "source": [ "!pip install dash\n", "!pip install --upgrade plotly" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "3St79DmIGPkc", "outputId": "71cdca20-c7f0-477e-c442-cdf09590dc34" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Requirement already satisfied: dash in /usr/local/lib/python3.11/dist-packages (3.0.4)\n", "Requirement already satisfied: Flask<3.1,>=1.0.4 in /usr/local/lib/python3.11/dist-packages (from dash) (3.0.3)\n", "Requirement already satisfied: Werkzeug<3.1 in /usr/local/lib/python3.11/dist-packages (from dash) (3.0.6)\n", "Requirement already satisfied: plotly>=5.0.0 in /usr/local/lib/python3.11/dist-packages (from dash) (6.1.0)\n", "Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.11/dist-packages (from dash) (8.7.0)\n", "Requirement already satisfied: typing-extensions>=4.1.1 in /usr/local/lib/python3.11/dist-packages (from dash) (4.13.2)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from dash) (2.32.3)\n", "Requirement already satisfied: retrying in /usr/local/lib/python3.11/dist-packages (from dash) (1.3.4)\n", "Requirement already satisfied: nest-asyncio in /usr/local/lib/python3.11/dist-packages (from dash) (1.6.0)\n", "Requirement already satisfied: setuptools in /usr/local/lib/python3.11/dist-packages (from dash) (75.2.0)\n", "Requirement already satisfied: Jinja2>=3.1.2 in /usr/local/lib/python3.11/dist-packages (from Flask<3.1,>=1.0.4->dash) (3.1.6)\n", "Requirement already satisfied: itsdangerous>=2.1.2 in /usr/local/lib/python3.11/dist-packages (from Flask<3.1,>=1.0.4->dash) (2.2.0)\n", "Requirement already satisfied: click>=8.1.3 in /usr/local/lib/python3.11/dist-packages (from Flask<3.1,>=1.0.4->dash) (8.2.0)\n", "Requirement already satisfied: blinker>=1.6.2 in /usr/local/lib/python3.11/dist-packages (from Flask<3.1,>=1.0.4->dash) (1.9.0)\n", "Requirement already satisfied: narwhals>=1.15.1 in /usr/local/lib/python3.11/dist-packages (from plotly>=5.0.0->dash) (1.39.0)\n", "Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from plotly>=5.0.0->dash) (24.2)\n", "Requirement already satisfied: MarkupSafe>=2.1.1 in /usr/local/lib/python3.11/dist-packages (from Werkzeug<3.1->dash) (3.0.2)\n", "Requirement already satisfied: zipp>=3.20 in /usr/local/lib/python3.11/dist-packages (from importlib-metadata->dash) (3.21.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->dash) (3.4.2)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests->dash) (3.10)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests->dash) (2.4.0)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests->dash) (2025.4.26)\n", "Requirement already satisfied: six>=1.7.0 in /usr/local/lib/python3.11/dist-packages (from retrying->dash) (1.17.0)\n", "Requirement already satisfied: plotly in /usr/local/lib/python3.11/dist-packages (6.1.0)\n", "Requirement already satisfied: narwhals>=1.15.1 in /usr/local/lib/python3.11/dist-packages (from plotly) (1.39.0)\n", "Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from plotly) (24.2)\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "" ], "application/javascript": [ "(async (port, path, width, height, cache, element) => {\n", " if (!google.colab.kernel.accessAllowed && !cache) {\n", " return;\n", " }\n", " element.appendChild(document.createTextNode(''));\n", " const url = await google.colab.kernel.proxyPort(port, {cache});\n", " const iframe = document.createElement('iframe');\n", " iframe.src = new URL(path, url).toString();\n", " iframe.height = height;\n", " iframe.width = width;\n", " iframe.style.border = 0;\n", " iframe.allow = [\n", " 'accelerometer',\n", " 'autoplay',\n", " 'camera',\n", " 'clipboard-read',\n", " 'clipboard-write',\n", " 'gyroscope',\n", " 'magnetometer',\n", " 'microphone',\n", " 'serial',\n", " 'usb',\n", " 'xr-spatial-tracking',\n", " ].join('; ');\n", " element.appendChild(iframe);\n", " })(8050, \"/\", \"100%\", 650, false, window.element)" ] }, "metadata": {} } ], "source": [ "import dash\n", "from dash import dcc, html\n", "import plotly.express as px\n", "import pandas as pd\n", "\n", "df = pd.DataFrame({\n", " 'x': [1, 2, 3, 4, 5],\n", " 'y': [10, 15, 13, 17, 14]\n", "})\n", "\n", "app = dash.Dash(__name__)\n", "\n", "app.layout = html.Div([\n", " dcc.Graph(\n", " id='example-graph',\n", " figure=px.scatter(df, x='x', y='y', title='Scatter Plot in Dash')\n", " )\n", "])\n", "\n", "if __name__ == '__main__':\n", " app.run(debug=True, port=8050)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "rHh4Tg9yGPh7" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }