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": {