{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Matplotlib 绘图\n", "\n", "创建上下文来配置 [Matplotlib 绘图](https://matplotlib.org/)。\n", "\n", "- `close`: 是否应在退出上下文后关闭图形;如果您稍后想要更新它,请设置为 `False`(默认:`True`)\n", "- `kwargs`: 应传递给 [`pyplot.figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html) 的参数,如 `figsize`" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from matplotlib import pyplot as plt\n", "from nicegui import ui\n", "\n", "with ui.pyplot(figsize=(3, 2)):\n", " x = np.linspace(0.0, 5.0)\n", " y = np.cos(2 * np.pi * x) * np.exp(-x)\n", " plt.plot(x, y, '-')\n", "\n", "# ui.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "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.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }