From f6c3260818c82d283b6e17809bc7533b3e5be66b Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Thu, 5 Oct 2023 18:45:43 +0200 Subject: [PATCH 1/5] feat(Matplotlib): Add Create Piechart --- Matplotlib/Matplotlib_Create_Piechart.ipynb | 252 ++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 Matplotlib/Matplotlib_Create_Piechart.ipynb diff --git a/Matplotlib/Matplotlib_Create_Piechart.ipynb b/Matplotlib/Matplotlib_Create_Piechart.ipynb new file mode 100644 index 0000000000..19ad114a20 --- /dev/null +++ b/Matplotlib/Matplotlib_Create_Piechart.ipynb @@ -0,0 +1,252 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "8c9ef857-6c86-47f6-8f65-57721efda695", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "cf7eb0f0-1f89-497f-bc54-a5fd83fc5a02", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Matplotlib - Create Piechart" + ] + }, + { + "cell_type": "markdown", + "id": "fa0d95b2-8af8-4f15-9f82-d2dbc77d2ada", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #matplotlib #piechart #datavisualization #plotting #python #visualization" + ] + }, + { + "cell_type": "markdown", + "id": "fb885501-a3c0-4b63-92df-c01fd3dae1c8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Firstname Lastname]()" + ] + }, + { + "cell_type": "markdown", + "id": "36705a1a-241c-483a-8735-a32b35a1d18f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-10-05 (Created: 2023-10-05)" + ] + }, + { + "cell_type": "markdown", + "id": "427a04f7-9e13-4c0c-bb0d-94a8d6f81bdb", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook will show how to create a piechart with Matplotlib. Pie charts are useful to represent proportions of a whole." + ] + }, + { + "cell_type": "markdown", + "id": "45c4bd95-2f4d-4574-8ded-cd8b6f04348a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n- [Matplotlib Pie Chart](https://matplotlib.org/stable/plot_types/stats/pie.html#sphx-glr-plot-types-stats-pie-py)\n- [Matplotlib Documentation](https://matplotlib.org/contents.html)" + ] + }, + { + "cell_type": "markdown", + "id": "042761b8-c31a-4bb6-8f57-eaca1a012cf0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "9b10f380-6ddc-48f5-90b4-9454ab324326", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "435a47b7-7012-4172-8565-a8b30ded1700", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "import matplotlib.pyplot as plt", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "a8fa608d-e932-4819-9a1b-50e0977daa65", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n- `labels`: list of labels for each slice of the pie chart\n- `sizes`: list of sizes for each slice of the pie chart" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5c87fee1-24bb-469a-9ccc-313ae6452c9f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "labels = [\"Frogs\", \"Hogs\", \"Dogs\", \"Logs\"]\nsizes = [15, 30, 45, 10]", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "aff0bef4-284d-4fe2-9a0d-67ce8505bf9d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "161eebd5-22b5-4d16-9791-46e6c457c163", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Create Pie Chart" + ] + }, + { + "cell_type": "markdown", + "id": "4b073715-6053-407e-888b-9a22a4f98b06", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "Create a pie chart with the given labels and sizes." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "448ee5c8-7b82-474c-9608-3a6cb5745660", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "plt.pie(sizes, labels=labels)\nplt.axis(\"equal\")", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "2a8540d3-b242-40a4-ae03-f814472275a3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "f57a2a82-c67b-4228-bdfc-f13d6acc2f8d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0c587394-c49d-4c86-93a1-97ad79cafe56", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "plt.show()", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "f0692308-7069-4700-a0f1-74953b63b8e2", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file From a7158a23c7b9ef1b67e24be53d6714062ca06ad2 Mon Sep 17 00:00:00 2001 From: M Sai Kiran Date: Sun, 8 Oct 2023 12:17:18 +0200 Subject: [PATCH 2/5] pie-chart-updated --- Matplotlib/Matplotlib_Create_Piechart.ipynb | 38 ++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Matplotlib/Matplotlib_Create_Piechart.ipynb b/Matplotlib/Matplotlib_Create_Piechart.ipynb index 19ad114a20..acada5107d 100644 --- a/Matplotlib/Matplotlib_Create_Piechart.ipynb +++ b/Matplotlib/Matplotlib_Create_Piechart.ipynb @@ -41,7 +41,7 @@ "tags": [] }, "source": [ - "**Author:** [Firstname Lastname]()" + "**Author:** [SaiKiran M]()" ] }, { @@ -74,7 +74,9 @@ "tags": [] }, "source": [ - "**References:**\n- [Matplotlib Pie Chart](https://matplotlib.org/stable/plot_types/stats/pie.html#sphx-glr-plot-types-stats-pie-py)\n- [Matplotlib Documentation](https://matplotlib.org/contents.html)" + "**References:**\n", + "- [Matplotlib Pie Chart](https://matplotlib.org/stable/plot_types/stats/pie.html#sphx-glr-plot-types-stats-pie-py)\n", + "- [Matplotlib Documentation](https://matplotlib.org/contents.html)" ] }, { @@ -107,8 +109,10 @@ "papermill": {}, "tags": [] }, - "source": "import matplotlib.pyplot as plt", - "outputs": [] + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt" + ] }, { "cell_type": "markdown", @@ -118,7 +122,9 @@ "tags": [] }, "source": [ - "### Setup variables\n- `labels`: list of labels for each slice of the pie chart\n- `sizes`: list of sizes for each slice of the pie chart" + "### Setup variables\n", + "- `labels`: list of labels for each slice of the pie chart\n", + "- `sizes`: list of sizes for each slice of the pie chart" ] }, { @@ -129,8 +135,11 @@ "papermill": {}, "tags": [] }, - "source": "labels = [\"Frogs\", \"Hogs\", \"Dogs\", \"Logs\"]\nsizes = [15, 30, 45, 10]", - "outputs": [] + "outputs": [], + "source": [ + "labels = [\"hotdogs\", \"salads\", \"sandwich\", \"burger\"] #visualize shares of food of a hotel by giving labels.\n", + "sizes = [14.5, 30.5, 45, 10] #here hotdogs shares corresponds to 14.5 and so on." + ] }, { "cell_type": "markdown", @@ -173,8 +182,11 @@ "papermill": {}, "tags": [] }, - "source": "plt.pie(sizes, labels=labels)\nplt.axis(\"equal\")", - "outputs": [] + "outputs": [], + "source": [ + "plt.pie(sizes, labels=labels, autopct='%1.1f%%')\n", + "plt.axis(\"equal\")" + ] }, { "cell_type": "markdown", @@ -206,8 +218,10 @@ "papermill": {}, "tags": [] }, - "source": "plt.show()", - "outputs": [] + "outputs": [], + "source": [ + "plt.show()" + ] }, { "cell_type": "markdown", @@ -249,4 +263,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} From 7ba457595a676cd91be5e8ed6611506c0c719660 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Mon, 9 Oct 2023 08:43:28 +0200 Subject: [PATCH 3/5] feat: add fig path variable + save and add asset in output --- Matplotlib/Matplotlib_Create_Piechart.ipynb | 41 +++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/Matplotlib/Matplotlib_Create_Piechart.ipynb b/Matplotlib/Matplotlib_Create_Piechart.ipynb index acada5107d..d6d5a4f4f6 100644 --- a/Matplotlib/Matplotlib_Create_Piechart.ipynb +++ b/Matplotlib/Matplotlib_Create_Piechart.ipynb @@ -124,7 +124,8 @@ "source": [ "### Setup variables\n", "- `labels`: list of labels for each slice of the pie chart\n", - "- `sizes`: list of sizes for each slice of the pie chart" + "- `sizes`: list of sizes for each slice of the pie chart\n", + "- `fig_path`: The file path or name for the output image file of the graph, saved as \"fig.png\"." ] }, { @@ -138,7 +139,8 @@ "outputs": [], "source": [ "labels = [\"hotdogs\", \"salads\", \"sandwich\", \"burger\"] #visualize shares of food of a hotel by giving labels.\n", - "sizes = [14.5, 30.5, 45, 10] #here hotdogs shares corresponds to 14.5 and so on." + "sizes = [14.5, 30.5, 45, 10] #here hotdogs shares corresponds to 14.5 and so on.\n", + "fig_path = \"fig.png\"" ] }, { @@ -185,7 +187,8 @@ "outputs": [], "source": [ "plt.pie(sizes, labels=labels, autopct='%1.1f%%')\n", - "plt.axis(\"equal\")" + "plt.axis(\"equal\")\n", + "plt.show()" ] }, { @@ -201,26 +204,50 @@ }, { "cell_type": "markdown", - "id": "f57a2a82-c67b-4228-bdfc-f13d6acc2f8d", + "id": "4f02c06a-c4ce-43d1-b2e9-693b44ecc7a0", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Display result" + "### Save figure" ] }, { "cell_type": "code", "execution_count": null, - "id": "0c587394-c49d-4c86-93a1-97ad79cafe56", + "id": "52dbb6ec-9828-490c-8d52-5261040e8e29", "metadata": { "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "plt.show()" + "fig.savefig(fig_path)" + ] + }, + { + "cell_type": "markdown", + "id": "fbe2f1c6-0312-4eae-a97d-d2ad17a8e70e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Share asset with naas" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a7623066-e856-43ba-a16c-328bd47a4c0e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "naas.asset.add(fig_path)" ] }, { From 791f6242d0efa87f4f71e8118395f507c192de21 Mon Sep 17 00:00:00 2001 From: M Sai Kiran Date: Mon, 9 Oct 2023 13:51:32 +0200 Subject: [PATCH 4/5] piechart-updated! --- Matplotlib/Matplotlib_Create_Piechart.ipynb | 46 ++++++++++----------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/Matplotlib/Matplotlib_Create_Piechart.ipynb b/Matplotlib/Matplotlib_Create_Piechart.ipynb index d6d5a4f4f6..2e8d2cfd17 100644 --- a/Matplotlib/Matplotlib_Create_Piechart.ipynb +++ b/Matplotlib/Matplotlib_Create_Piechart.ipynb @@ -41,7 +41,7 @@ "tags": [] }, "source": [ - "**Author:** [SaiKiran M]()" + "**Author:** [SaiKiran M](www.linkedin.com/in/msaikiran9)" ] }, { @@ -111,7 +111,8 @@ }, "outputs": [], "source": [ - "import matplotlib.pyplot as plt" + "import matplotlib.pyplot as plt\n", + "import naas" ] }, { @@ -124,8 +125,7 @@ "source": [ "### Setup variables\n", "- `labels`: list of labels for each slice of the pie chart\n", - "- `sizes`: list of sizes for each slice of the pie chart\n", - "- `fig_path`: The file path or name for the output image file of the graph, saved as \"fig.png\"." + "- `sizes`: list of sizes for each slice of the pie chart" ] }, { @@ -138,9 +138,11 @@ }, "outputs": [], "source": [ + "#inputs:\n", "labels = [\"hotdogs\", \"salads\", \"sandwich\", \"burger\"] #visualize shares of food of a hotel by giving labels.\n", "sizes = [14.5, 30.5, 45, 10] #here hotdogs shares corresponds to 14.5 and so on.\n", - "fig_path = \"fig.png\"" + "#outputs:\n", + "piechart_path=\"pie.png\"" ] }, { @@ -188,7 +190,7 @@ "source": [ "plt.pie(sizes, labels=labels, autopct='%1.1f%%')\n", "plt.axis(\"equal\")\n", - "plt.show()" + "plt.savefig(piechart_path)" ] }, { @@ -204,62 +206,58 @@ }, { "cell_type": "markdown", - "id": "4f02c06a-c4ce-43d1-b2e9-693b44ecc7a0", + "id": "f57a2a82-c67b-4228-bdfc-f13d6acc2f8d", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Save figure" + "### Display result" ] }, { "cell_type": "code", "execution_count": null, - "id": "52dbb6ec-9828-490c-8d52-5261040e8e29", + "id": "0c587394-c49d-4c86-93a1-97ad79cafe56", "metadata": { "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "fig.savefig(fig_path)" + "plt.show()" ] }, { "cell_type": "markdown", - "id": "fbe2f1c6-0312-4eae-a97d-d2ad17a8e70e", + "id": "f0692308-7069-4700-a0f1-74953b63b8e2", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Share asset with naas" + " " ] }, { "cell_type": "code", "execution_count": null, - "id": "a7623066-e856-43ba-a16c-328bd47a4c0e", + "id": "c23f483f-ff77-4fbd-83a1-fb12b59928b7", "metadata": { - "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "naas.asset.add(fig_path)" + "naas.asset.add(piechart_path)" ] }, { - "cell_type": "markdown", - "id": "f0692308-7069-4700-a0f1-74953b63b8e2", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - " " - ] + "cell_type": "code", + "execution_count": null, + "id": "52c66aad-cb4d-44da-b9f5-116c6e65d6ec", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From 89627b6e57f5553b8302c18f11642763d17d3b8f Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Mon, 9 Oct 2023 19:29:16 +0200 Subject: [PATCH 5/5] feat: ad savefig in output section and describe variable "fig_path" in input --- Matplotlib/Matplotlib_Create_Piechart.ipynb | 34 +++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Matplotlib/Matplotlib_Create_Piechart.ipynb b/Matplotlib/Matplotlib_Create_Piechart.ipynb index 2e8d2cfd17..530856853e 100644 --- a/Matplotlib/Matplotlib_Create_Piechart.ipynb +++ b/Matplotlib/Matplotlib_Create_Piechart.ipynb @@ -75,8 +75,7 @@ }, "source": [ "**References:**\n", - "- [Matplotlib Pie Chart](https://matplotlib.org/stable/plot_types/stats/pie.html#sphx-glr-plot-types-stats-pie-py)\n", - "- [Matplotlib Documentation](https://matplotlib.org/contents.html)" + "- [Matplotlib Pie Chart](https://matplotlib.org/stable/plot_types/stats/pie.html#sphx-glr-plot-types-stats-pie-py)" ] }, { @@ -125,7 +124,8 @@ "source": [ "### Setup variables\n", "- `labels`: list of labels for each slice of the pie chart\n", - "- `sizes`: list of sizes for each slice of the pie chart" + "- `sizes`: list of sizes for each slice of the pie chart\n", + "- `fig_path`: The file path or name for the output image file of the graph, saved as \"fig.png\"." ] }, { @@ -138,11 +138,12 @@ }, "outputs": [], "source": [ - "#inputs:\n", + "# Inputs\n", "labels = [\"hotdogs\", \"salads\", \"sandwich\", \"burger\"] #visualize shares of food of a hotel by giving labels.\n", "sizes = [14.5, 30.5, 45, 10] #here hotdogs shares corresponds to 14.5 and so on.\n", - "#outputs:\n", - "piechart_path=\"pie.png\"" + "\n", + "# Outputs\n", + "fig_path = \"pie.png\"" ] }, { @@ -190,7 +191,7 @@ "source": [ "plt.pie(sizes, labels=labels, autopct='%1.1f%%')\n", "plt.axis(\"equal\")\n", - "plt.savefig(piechart_path)" + "plt.show()" ] }, { @@ -206,55 +207,56 @@ }, { "cell_type": "markdown", - "id": "f57a2a82-c67b-4228-bdfc-f13d6acc2f8d", + "id": "f7413927-a8ba-4f8b-9939-15d4e1b095e9", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Display result" + "### Save figure" ] }, { "cell_type": "code", "execution_count": null, - "id": "0c587394-c49d-4c86-93a1-97ad79cafe56", + "id": "498629c1-6442-4694-bcdd-35ffd85a94a8", "metadata": { "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "plt.show()" + "plt.savefig(fig_path)" ] }, { "cell_type": "markdown", - "id": "f0692308-7069-4700-a0f1-74953b63b8e2", + "id": "0341a2a0-4905-45dd-a8c8-f1827cf7d212", "metadata": { "papermill": {}, "tags": [] }, "source": [ - " " + "### Share asset with naas" ] }, { "cell_type": "code", "execution_count": null, - "id": "c23f483f-ff77-4fbd-83a1-fb12b59928b7", + "id": "063f9203-12cd-4705-b0cd-93cc9113acb4", "metadata": { + "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "naas.asset.add(piechart_path)" + "naas.asset.add(fig_path)" ] }, { "cell_type": "code", "execution_count": null, - "id": "52c66aad-cb4d-44da-b9f5-116c6e65d6ec", + "id": "672cd7bd-98e3-451f-b99f-4d5e9a3e9750", "metadata": {}, "outputs": [], "source": []