From 1e3d257985ca6ccc544134458043499489bda606 Mon Sep 17 00:00:00 2001 From: Christoph Giess Date: Mon, 17 Jul 2023 17:50:02 +0200 Subject: [PATCH] =?UTF-8?q?Exportieren=20von=20Grafiken=20bei=20matplotlib?= =?UTF-8?q?=20&=20pandas=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jupyter_book/03_matplotlib.ipynb | 21 ++++++++++++++++++++- jupyter_book/05_pandas_visu.ipynb | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/jupyter_book/03_matplotlib.ipynb b/jupyter_book/03_matplotlib.ipynb index 9bf29eb..bfa29ba 100644 --- a/jupyter_book/03_matplotlib.ipynb +++ b/jupyter_book/03_matplotlib.ipynb @@ -338,7 +338,26 @@ "plt.legend(['sin(x)', 'cos(x)']);\n", "plt.show()" ] - } + }, + { + "cell_type": "markdown", + "id": "470cd36c-2758-4f6f-b359-3a6adfb127dc", + "metadata": {}, + "source": [ + "## Grafiken speichern/exportieren\n", + "\n", + "Bilder können nicht nur angezeigt sondern auch gespeichert werden. Dies muss *vor* dem Aufruf von `plt.show()` geschehen:\n", + "\n", + "```\n", + "plt.savefig('sin_cos.png');\n", + "plt.savefig('sin_cos.pdf');\n", + "plt.savefig('sin_cos.svg');\n", + "plt.savefig('sin_cos.png', dpi=300, transparent=True, bbox_inches='tight')\n", + "\n", + "plt.show()\n", + "```" + ] + } ], "metadata": { "kernelspec": { diff --git a/jupyter_book/05_pandas_visu.ipynb b/jupyter_book/05_pandas_visu.ipynb index 995065d..604affd 100644 --- a/jupyter_book/05_pandas_visu.ipynb +++ b/jupyter_book/05_pandas_visu.ipynb @@ -821,6 +821,22 @@ "d.groupby(\"Typ\")[\"Preis\"].sum().plot(kind=\"pie\");\n", "plt.show()" ] + }, + { + "cell_type": "markdown", + "id": "e6c9a7fb-b374-4743-8b37-77fc8de79cbd", + "metadata": {}, + "source": [ + "## Grafiken speichern/exportieren\n", + "\n", + "Zum speichern der Grafiken muss man sich zuerst mittels `get_figure()` einen Verweis auf die Grafik holen ", + "Danach kann man über diese Referenz die Grafik in verschiedenen Formaten speichern:\n", + "```\n", + "fig = d.groupby(\"Typ\")[\"Preis\"].sum().plot(kind=\"pie\").get_figure();\n", + "fig.savefig('pie.png');\n", + "fig.savefig('pie.pdf');\n", + "```" + ] } ], "metadata": {