{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# A simple plotting example\n",
    "\n",
    "A plotting example with a few simple tweaks\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 21100 characters]",
      "text/plain": [
       "<Figure size 360x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib\n",
    "\n",
    "# Agg 后端 = Anti-Grain Geometry 后端\n",
    "# 不需要弹窗口、只想“静默”出图（服务器、脚本、批量、CRON、Web 后台）就用 Agg\n",
    "#matplotlib.use(\"Agg\")\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# 新建图窗：宽 5 英寸、高 4 英寸，分辨率 72 dpi（Agg 后端，仅供保存）\n",
    "fig = plt.figure(figsize=(5, 4), dpi=72)\n",
    "\n",
    "# 添加几乎铺满整张图的坐标轴，边距仅 1 %\n",
    "axes = fig.add_axes((0.01, 0.01, 0.98, 0.98))\n",
    "\n",
    "# 生成 0→2 的 200 个等距点，作为横坐标\n",
    "x = np.linspace(0, 2, 200)\n",
    "# 计算 1 Hz 正弦波，y = sin(2πx)\n",
    "y = np.sin(2 * np.pi * x)\n",
    "\n",
    "# 绘制正弦曲线：黑色、线宽 0.25 pt\n",
    "plt.plot(x, y, lw=0.25, c=\"k\")\n",
    "\n",
    "# 设置坐标轴刻度密度：x 每 0.1 一格，y 每 0.1 一格\n",
    "plt.xticks(np.arange(0.0, 2.0, 0.1))\n",
    "plt.yticks(np.arange(-1.0, 1.0, 0.1))\n",
    "\n",
    "# 打开网格线，便于观察波形\n",
    "plt.grid()\n",
    "\n",
    "# 在非交互 Agg 下，plt.show() 不会弹窗；如要保存可改用 plt.savefig(\"sin.png\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
