{"id":117,"date":"2026-08-06T00:31:16","date_gmt":"2026-08-05T16:31:16","guid":{"rendered":"https:\/\/ltrainyard.icu\/?p=117"},"modified":"2026-08-06T00:46:07","modified_gmt":"2026-08-05T16:46:07","slug":"day-25-matplotlib-%e5%8f%af%e8%a7%86%e5%8c%96%ef%bc%9afigure-%e4%b8%8e-axes%e3%80%81%e6%8a%98%e7%ba%bf-%e6%9f%b1%e7%8a%b6%e5%9b%be","status":"publish","type":"post","link":"https:\/\/ltrainyard.icu\/index.php\/2026\/08\/06\/day-25-matplotlib-%e5%8f%af%e8%a7%86%e5%8c%96%ef%bc%9afigure-%e4%b8%8e-axes%e3%80%81%e6%8a%98%e7%ba%bf-%e6%9f%b1%e7%8a%b6%e5%9b%be\/","title":{"rendered":"| Day 25 | matplotlib \u53ef\u89c6\u5316\uff1afigure \u4e0e axes\u3001\u6298\u7ebf \/ \u67f1\u72b6\u56fe |"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1 figure \u4e0e axes \u2014\u2014 \u753b\u5e03\u4e0e\u5750\u6807\u7cfb<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>figure<\/strong>\uff08\u753b\u5e03\uff09\u662f\u6574\u5f20\u56fe\uff0c<strong>axes<\/strong>\uff08\u5750\u6807\u7cfb\uff09\u662f\u753b\u5e03\u4e0a\u771f\u6b63\u753b\u56fe\u7684\u90a3\u5757\u533a\u57df\u3002matplotlib \u6240\u6709\u7ed8\u56fe\u90fd\u9075\u5faa\u540c\u4e00\u6a21\u5f0f\uff1a\u5148\u6709\u753b\u5e03\uff0c\u518d\u5efa\u5750\u6807\u7cfb\uff0c\u6700\u540e\u5f80\u91cc\u753b\u4e1c\u897f\u3002\u4e0d\u7406\u89e3\u8fd9\u4e24\u4e2a\u6982\u5ff5\uff0c\u753b\u591a\u5b50\u56fe\u3001\u8c03\u5e03\u5c40\u65f6\u4e00\u5b9a\u7ed5\u6655\u2014\u2014\u8fd9\u662f\u4eca\u5929\u6700\u91cd\u8981\u7684 10%\u3002\u524d\u9762 24 \u5929\u6211\u4eec\u5b66\u4f1a\u5904\u7406\u6570\u636e\uff0c\u4f46\u4e00\u5806\u6570\u5b57\u6446\u5728\u90a3\u91cc\uff0c\u4eba\u5f88\u96be\u4e00\u773c\u770b\u51fa\u89c4\u5f8b\u2014\u2014<strong>\u56fe\u8868\u662f\u7ed9\u773c\u775b\u770b\u7684<\/strong>\uff0c\u4eca\u5929\u5b66 Python \u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93 matplotlib\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>plt.subplots()<\/code> \u4e00\u6b21\u521b\u5efa\u4e24\u8005\uff0c\u8fd4\u56de <code>(figure, axes)<\/code>\u3002<code>plt.plot()<\/code> \u8fd9\u7c7b\u5feb\u6377\u5199\u6cd5\u5185\u90e8\u4e5f\u5077\u5077\u521b\u5efa\u4e86\u9ed8\u8ba4 figure + \u9ed8\u8ba4 axes\uff08pyplot \u72b6\u6001\u673a\u673a\u5236\uff09\u3002\u4e00\u4e2a figure \u80fd\u88c5\u591a\u4e2a axes\uff1a<code>plt.subplots(1, 2)<\/code> \u8fd4\u56de\u300c\u4e00\u884c\u4e24\u5217\u300d\u7684 axes \u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u662f\u72ec\u7acb\u5750\u6807\u7cfb\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">figure \u50cf\u4e00\u5f20<strong>\u753b\u7eb8<\/strong>\uff0caxes \u50cf\u753b\u7eb8\u4e0a\u7684<strong>\u53d6\u666f\u6846<\/strong>\uff1a\u4e00\u5f20\u7eb8\u53ef\u6392\u597d\u51e0\u4e2a\u53d6\u666f\u6846\uff08\u591a\u5b50\u56fe\uff09\uff0c\u6574\u5f20\u7eb8\u5c31\u662f\u6700\u7ec8\u4ea4\u7ed9\u522b\u4eba\u7684\u90a3\u5f20\u56fe\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>figure \u4e0e axes \u7684\u5206\u5de5<\/strong>\uff08\u79bb\u7ebf\u53ef\u8dd1\uff0c\u56fe\u4fdd\u5b58\u5230 Temp \u76ee\u5f55\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport matplotlib.pyplot as plt\n\nplt.rcParams&#91;\"font.sans-serif\"] = &#91;\"SimHei\", \"Microsoft YaHei\"]\nplt.rcParams&#91;\"axes.unicode_minus\"] = False\n\nos.makedirs(\"Temp\", exist_ok=True)      # \u786e\u4fdd Temp \u76ee\u5f55\u5b58\u5728\nfig, ax = plt.subplots()                # \u753b\u5e03 + \u5750\u6807\u7cfb\nax.plot(&#91;1, 2, 3, 4], &#91;1, 4, 9, 16])    # \u5f80\u5750\u6807\u7cfb\u91cc\u753b\u6298\u7ebf\nax.set_title(\"y = x^2\")                 # axes \u81ea\u5e26\u8bbe\u7f6e\u65b9\u6cd5\nplt.savefig(\"Temp\/day25_fig_axes.png\", dpi=150)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>fig, ax = plt.subplots()<\/code> \u540c\u65f6\u62ff\u5230\u753b\u5e03\u548c\u5750\u6807\u7cfb\uff1b<code>ax.plot(...)<\/code> \u5f80<strong>\u5750\u6807\u7cfb<\/strong>\u91cc\u753b\u7ebf\uff08\u6ce8\u610f\u662f <code>ax.<\/code> \u4e0d\u662f <code>plt.<\/code>\uff09\uff1b<code>savefig<\/code> \u4fdd\u5b58\u7684\u662f<strong>\u6574\u4e2a figure<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u4e00\u4e2a\u753b\u5e03\u88c5\u4e24\u4e2a\u5750\u6807\u7cfb<\/strong>\uff08\u79bb\u7ebf\u53ef\u8dd1\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fig, axes = plt.subplots(1, 2, figsize=(8, 3))  # 1 \u884c 2 \u5217\naxes&#91;0].plot(&#91;1, 2, 3], &#91;1, 2, 3])              # \u5de6\u6846\uff1a\u76f4\u7ebf\naxes&#91;1].bar(&#91;\"A\", \"B\", \"C\"], &#91;3, 1, 2])         # \u53f3\u6846\uff1a\u67f1\u72b6\nplt.tight_layout()\nplt.savefig(\"Temp\/day25_subplots.png\", dpi=150)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>subplots(1, 2)<\/code> \u8fd4\u56de\u5750\u6807\u7cfb<strong>\u6570\u7ec4<\/strong>\uff0c\u6309\u4e0b\u6807 <code>axes[0]<\/code> \/ <code>axes[1]<\/code> \u5206\u522b\u753b\u56fe\u3002\u591a\u5b50\u56fe\u7528 <code>plt.subplots(2, 2)<\/code> \u540e\u7528 <code>axes[0, 0].plot(...)<\/code> \u6307\u5b9a\u5b50\u56fe\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>axes.plot(...)<\/code>\uff08axes \u662f\u6570\u7ec4\u65f6\uff09 \u2192 \u95ee\u9898\uff1a\u6570\u7ec4\u6ca1\u6709 <code>.plot<\/code>\uff0c\u62a5 <code>AttributeError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u6309\u4e0b\u6807\u53d6\u5355\u4e2a\uff1a<code>axes[0].plot(...)<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>plt.plot()<\/code> \u548c <code>ax.set_title()<\/code> \u6df7\u7528 \u2192 \u95ee\u9898\uff1a\u6807\u9898\u52a0\u4e0d\u5230\u521a\u753b\u7684\u90a3\u5f20\u56fe\u4e0a \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u8981\u4e48\u5168\u7528 <code>plt.xxx()<\/code>\uff0c\u8981\u4e48\u5168\u7528 <code>ax.xxx()<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1afigure \u662f\u753b\u7eb8\uff0caxes \u662f\u53d6\u666f\u6846\uff1b\u4e00\u5f20\u7eb8\u53ef\u6392\u591a\u6846\uff0c\u5148\u5efa\u540e\u753b\u4e0d\u614c\u5fd9\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2 \u7ed8\u56fe\u4e09\u6b65\u6cd5 \u2014\u2014 \u6570\u636e\u3001\u7c7b\u578b\u3001\u6837\u5f0f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4efb\u4f55\u4e00\u5f20 matplotlib \u56fe\u8868\u90fd\u53ea\u6709\u4e09\u6b65\uff1a<strong>\u51c6\u5907\u6570\u636e \u2192 \u9009\u56fe\u8868\u7c7b\u578b\u5e76\u4f20\u5165\u6570\u636e \u2192 \u8c03\u6837\u5f0f<\/strong>\u3002\u4eca\u5929\u8981\u5b66\u7684\u56db\u79cd\u56fe\u90fd\u662f\u8fd9\u4e09\u6b65\u7684\u53d8\u4f53\u3002\u628a\u300c\u4e09\u6b65\u6cd5\u300d\u523b\u5728\u8111\u5b50\u91cc\uff0c\u9047\u5230\u65b0\u56fe\u8868\u7c7b\u578b\u4e5f\u4e0d\u4f1a\u614c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u79cd\u56fe\u5bf9\u5e94\u4e00\u4e2a\u7ed8\u56fe\u51fd\u6570\uff1a<code>plt.plot(x, y)<\/code> \u628a\u70b9\u8fde\u6210\u7ebf\uff08\u8fde\u7eed\u6570\u636e\u770b\u8d8b\u52bf\uff09\uff1b<code>plt.bar(x, y)<\/code> \u4e3a\u6bcf\u4e2a\u7c7b\u522b\u753b\u67f1\u5b50\uff08\u79bb\u6563\u7c7b\u522b\u6bd4\u5927\u5c0f\uff09\uff1b<code>plt.scatter(x, y)<\/code> \u53ea\u753b\u70b9\u4e0d\u8fde\u7ebf\uff08\u627e\u4e24\u4e2a\u53d8\u91cf\u7684\u5173\u7cfb\uff09\uff1b<code>plt.pie(values)<\/code> \u6309\u5360\u6bd4\u753b\u6247\u5f62\uff08\u770b\u90e8\u5206\u5360\u6574\u4f53\u591a\u5c11\uff09\u3002\u6837\u5f0f\u53c2\u6570\uff1a<code>color<\/code> \u989c\u8272\u3001<code>linestyle<\/code> \u7ebf\u578b\uff08<code>--<\/code> \u865a\u7ebf\uff09\u3001<code>marker<\/code> \u6570\u636e\u70b9\u6807\u8bb0\uff08<code>o<\/code> \u5706\u70b9\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u50cf\u505a PPT \u56fe\u8868\uff1a\u5148\u6709\u6570\u636e\u8868\uff08\u51c6\u5907\u6570\u636e\uff09\uff0c\u518d\u9009\u56fe\u8868\u7c7b\u578b\uff08\u67f1\u72b6\u8fd8\u662f\u6298\u7ebf\uff09\uff0c\u6700\u540e\u6362\u914d\u8272\uff08\u8c03\u6837\u5f0f\uff09\u3002\u6570\u636e\u6ca1\u51c6\u5907\u597d\u5c31\u9009\u7c7b\u578b\uff0c\u7b49\u4e8e\u6ca1\u91cf\u5c3a\u5bf8\u5c31\u88c1\u8863\u670d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u4e09\u6b65\u6cd5\u753b\u4e00\u5f20\u7cbe\u81f4\u7684\u6298\u7ebf\u56fe<\/strong>\uff08\u79bb\u7ebf\u53ef\u8dd1\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport matplotlib.pyplot as plt\n\nplt.rcParams&#91;\"font.sans-serif\"] = &#91;\"SimHei\", \"Microsoft YaHei\"]\nplt.rcParams&#91;\"axes.unicode_minus\"] = False\n\nos.makedirs(\"Temp\", exist_ok=True)\nmonths = &#91;1, 2, 3, 4, 5, 6]          # \u7b2c\u4e00\u6b65\uff1a\u51c6\u5907\u6570\u636e\ntemperature = &#91;5, 8, 15, 22, 28, 33]\n\nplt.plot(months, temperature, color=\"red\", linestyle=\"--\", marker=\"o\")\nplt.title(\"\u4e0a\u534a\u5e74\u6c14\u6e29\u53d8\u5316\")\nplt.xlabel(\"\u6708\u4efd\")\nplt.ylabel(\"\u6c14\u6e29\uff08\u2103\uff09\")\nplt.savefig(\"Temp\/day25_line.png\", dpi=150)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u51c6\u5907\u4e24\u4e2a\u7b49\u957f\u5217\u8868 <code>x=months<\/code>\u3001<code>y=temperature<\/code>\uff1b<code>plt.plot(...)<\/code> \u753b\u6298\u7ebf\uff0c<code>color<\/code> \u7ea2\u3001<code>linestyle=\"--\"<\/code> \u865a\u7ebf\u3001<code>marker=\"o\"<\/code> \u6570\u636e\u70b9\u753b\u5708\uff1b<code>title\/xlabel\/ylabel<\/code> \u914d\u9f50\u4e09\u8981\u7d20\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u56db\u79cd\u56fe\u7684\u9009\u62e9<\/strong>\uff1a\u6298\u7ebf\u770b\u8d8b\u52bf\u3001\u67f1\u72b6\u6bd4\u5927\u5c0f\u3001\u6563\u70b9\u627e\u76f8\u5173\u3001\u997c\u56fe\u770b\u5360\u6bd4\u3002\u6a2a\u5411\u67f1\u72b6\u56fe <code>barh<\/code> \u9002\u5408\u79d1\u76ee\u540d\u5f88\u957f\u7684\u60c5\u51b5\uff1b\u997c\u56fe <code>autopct=\"%.1f%%\"<\/code> \u5728\u6bcf\u5757\u4e0a\u663e\u793a\u767e\u5206\u6bd4\uff0c<code>explode<\/code> \u8ba9\u67d0\u5757\u7a81\u51fa\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>plt.plot(x)<\/code> \u53ea\u4f20\u4e00\u4e2a\u5217\u8868 \u2192 \u95ee\u9898\uff1ax \u81ea\u52a8\u53d8\u6210\u4e0b\u6807 0,1,2&#8230;\uff0c\u56fe\u4e0e\u9884\u671f\u4e0d\u7b26 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u6210\u5bf9\u4f20\uff1a<code>plt.plot(x, y)<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1ax\u3001y \u957f\u5ea6\u4e0d\u540c \u2192 \u95ee\u9898\uff1a\u62a5 <code>ValueError: x and y must have same first dimension<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148 <code>print(len(x), len(y))<\/code> \u68c0\u67e5\u5bf9\u9f50\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u5148\u6570\u636e\u540e\u7c7b\u578b\u518d\u6837\u5f0f\uff0c\u4e09\u6b65\u753b\u56fe\u4e0d\u614c\u5f20\uff1b\u8d8b\u52bf\u6298\u7ebf\u3001\u6bd4\u5927\u5c0f\u67f1\u72b6\u3001\u627e\u5173\u7cfb\u6563\u70b9\u3001\u770b\u5360\u6bd4\u997c\u56fe\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3 \u4e2d\u6587\u663e\u793a\u4e0e rcParams \u2014\u2014 \u5b57\u4f53\u914d\u7f6e<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">matplotlib \u7684\u9ed8\u8ba4\u5b57\u4f53<strong>\u4e0d\u542b\u4e2d\u6587\u5b57\u5f62<\/strong>\uff0c\u76f4\u63a5\u753b\u4e2d\u6587\u6807\u9898\u4f1a\u53d8\u6210\u65b9\u6846\uff08\u25a1\uff09\u3002\u89e3\u51b3\u529e\u6cd5\uff1a\u811a\u672c\u5f00\u5934\u7528 <code>plt.rcParams<\/code> \u6307\u5b9a\u7cfb\u7edf\u4e2d\u6587\u5b57\u4f53\u3002<strong>\u6ce8\u610f\uff1a\u4e0d\u540c\u7cfb\u7edf\u7684\u5b57\u4f53\u540d\u4e0d\u540c<\/strong>\u2014\u2014Windows \u81ea\u5e26 SimHei\uff08\u9ed1\u4f53\uff09\uff0cmacOS \u662f &#8220;Arial Unicode MS&#8221; \u6216 &#8220;PingFang SC&#8221;\uff0cLinux \u5e38\u89c1 &#8220;Noto Sans CJK SC&#8221;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>plt.rcParams<\/code> \u662f matplotlib \u7684\u5168\u5c40\u914d\u7f6e\u5b57\u5178\uff0c<code>font.sans-serif<\/code> \u662f\u300c\u65e0\u886c\u7ebf\u5b57\u4f53\u5019\u9009\u5217\u8868\u300d\uff0c\u6e32\u67d3\u65f6\u6309\u5217\u8868\u987a\u5e8f\u627e\u5b57\u4f53\uff0c\u627e\u4e0d\u5230\u4e2d\u6587\u5b57\u5f62\u5c31\u9000\u56de\u9ed8\u8ba4\u82f1\u6587\u5b57\u4f53\uff0c\u4e2d\u6587\u53d8\u65b9\u6846\uff08\u4e13\u4e1a\u8bf4\u6cd5\u53eb tofu\uff09\u3002<code>axes.unicode_minus = False<\/code> \u8ba9\u8d1f\u53f7\u7528\u666e\u901a\u8fde\u5b57\u7b26\u300c-\u300d\u6e32\u67d3\uff0c\u5426\u5219\u8d1f\u53f7\u6309 Unicode \u6570\u5b66\u7b26\u53f7\u5904\u7406\u7167\u6837\u53d8\u65b9\u6846\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u50cf\u7ed9\u6253\u5370\u673a\u88c5\u5b57\u5e93\uff1a\u6253\u5370\u673a\uff08matplotlib\uff09\u9ed8\u8ba4\u53ea\u8ba4\u8bc6\u82f1\u6587\u5b57\u5e93\uff0c\u6253\u4e2d\u6587\u5c31\u662f \u25a1\u25a1\u25a1\uff1b\u88c5\u4e0a\u4e2d\u6587\u5b57\u5e93\uff08rcParams \u6307\u5b9a\u5b57\u4f53\uff09\u4e4b\u540e\uff0c\u4e2d\u6587\u624d\u80fd\u6b63\u5e38\u6253\u5370\u51fa\u6765\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u914d\u7f6e\u4e2d\u6587\u5b57\u4f53 + \u9a8c\u8bc1\u5b57\u4f53\u771f\u7684\u53ef\u7528<\/strong>\uff08\u79bb\u7ebf\u53ef\u8dd1\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport matplotlib.pyplot as plt\nimport matplotlib.font_manager as fm\n\nplt.rcParams&#91;\"font.sans-serif\"] = &#91;\"SimHei\", \"Microsoft YaHei\"]\nplt.rcParams&#91;\"axes.unicode_minus\"] = False\n\nos.makedirs(\"Temp\", exist_ok=True)\nfonts = &#91;f.name for f in fm.fontManager.ttflist]   # \u7cfb\u7edf\u5df2\u6ce8\u518c\u5b57\u4f53\u540d\nprint(\"SimHei \u53ef\u7528\uff1a\", \"SimHei\" in fonts)\n\nplt.plot(&#91;1, 2, 3, 4], &#91;10, 5, -5, 12], marker=\"o\")\nplt.title(\"\u4e2d\u6587\u6807\u9898\u6d4b\u8bd5\uff1a\u6c14\u6e29\u53d8\u5316\")\nplt.savefig(\"Temp\/day25_chinese.png\", dpi=150)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>fm.fontManager.ttflist<\/code> \u662f\u7cfb\u7edf\u5df2\u6ce8\u518c\u5b57\u4f53\u5217\u8868\uff0c<code>\"SimHei\" in fonts<\/code> \u68c0\u67e5\u9ed1\u4f53\u662f\u5426\u53ef\u7528\u2014\u2014<strong>\u5efa\u8bae\u5148\u8dd1\u8fd9\u884c\u786e\u8ba4\u5b57\u4f53\u5b58\u5728<\/strong>\u518d\u753b\u56fe\u3002\u8fd0\u884c\u540e\u4e2d\u6587\u6807\u9898\u6e05\u6e05\u695a\u695a\uff0c\u7eb5\u8f74\u8d1f\u6570 -5 \u4e5f\u663e\u793a\u6b63\u5e38\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u6240\u6709\u753b\u56fe\u811a\u672c\u5f00\u5934\u7684\u6807\u51c6\u4e24\u884c<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import matplotlib.pyplot as plt\nplt.rcParams&#91;\"font.sans-serif\"] = &#91;\"SimHei\", \"Microsoft YaHei\"]\nplt.rcParams&#91;\"axes.unicode_minus\"] = False   # \u8ba9\u8d1f\u53f7\u6b63\u5e38\u663e\u793a\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u53ea\u914d <code>font.sans-serif<\/code> \u4e0d\u914d <code>axes.unicode_minus<\/code> \u2192 \u95ee\u9898\uff1a\u8d1f\u53f7\uff08\u5982 -5\uff09\u663e\u793a\u6210\u65b9\u6846 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u4e24\u884c\u4e00\u8d77\u5199\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1amacOS \/ Linux \u4e0a\u7167\u6284 SimHei \u2192 \u95ee\u9898\uff1a\u7cfb\u7edf\u6ca1\u88c5\u9ed1\u4f53\uff0c\u4e2d\u6587\u8fd8\u662f\u65b9\u6846 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u6362\u6210\u672c\u673a\u5b57\u4f53\u540d\uff08macOS \u7528 &#8220;Arial Unicode MS&#8221;\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u5f00\u5934\u4e24\u884c rcParams\uff0c\u4e2d\u6587\u65b9\u6846\u4e0d\u518d\u89c1\uff1b\u5b57\u4f53\u540d\u968f\u7cfb\u7edf\u6362\uff0c\u8d1f\u53f7\u914d\u7f6e\u522b\u5fd8\u5173\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4 savefig \u4fdd\u5b58\u56fe\u7247 \u2014\u2014 \u5148\u4fdd\u5b58\uff0c\u518d\u663e\u793a<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>plt.savefig(\"\u6587\u4ef6\u540d.png\", dpi=150)<\/code> \u628a\u5f53\u524d figure \u4fdd\u5b58\u6210\u56fe\u7247\u6587\u4ef6\uff0c\u62a5\u544a\u3001PPT\u3001\u4f5c\u4e1a\u63d0\u4ea4\u5168\u9760\u5b83\u3002\u670d\u52a1\u5668\u6ca1\u6709\u56fe\u5f62\u754c\u9762\u3001\u4ee5\u53ca\u81ea\u52a8\u5316\u6279\u91cf\u51fa\u56fe\u7684\u573a\u666f\uff0c<code>savefig<\/code> \u662f<strong>\u552f\u4e00<\/strong>\u7684\u53d6\u56fe\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>savefig<\/code> \u6309\u683c\u5f0f\u5199\u5165\u6587\u4ef6\uff1a<code>.png<\/code> \u4f4d\u56fe\uff08\u6e05\u6670\u5ea6\u7531 <code>dpi<\/code> \u63a7\u5236\uff09\u3001<code>.jpg<\/code> \u4f4d\u56fe\uff08\u4f53\u79ef\u5c0f\u4f46\u6709\u635f\uff09\u3001<code>.svg<\/code> \/ <code>.pdf<\/code> \u77e2\u91cf\u56fe\uff08\u65e0\u9650\u653e\u5927\u4e0d\u6a21\u7cca\uff09\u3002<code>dpi<\/code>\uff08dots per inch\uff0c\u6bcf\u82f1\u5bf8\u70b9\u6570\uff09\u8d8a\u9ad8\u8d8a\u6e05\u6670\uff0c\u9ed8\u8ba4 100\uff0c\u5199\u62a5\u544a\u7528 150~300\u3002<strong>\u4e3a\u4ec0\u4e48\u5148 savefig \u518d show<\/strong>\uff1a<code>show()<\/code> \u8fdb\u5165\u4ea4\u4e92\u5c55\u793a\u540e\uff0c\u67d0\u4e9b\u73af\u5883\u4e0b\u753b\u5e03\u5185\u5bb9\u4f1a\u88ab\u91cd\u7f6e\uff0c\u4e4b\u540e\u518d savefig \u53ef\u80fd\u5f97\u5230\u7a7a\u767d\u56fe\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u50cf\u624b\u673a\u62cd\u7167\u540e\u7acb\u523b\u300c\u4fdd\u5b58\u5230\u76f8\u518c\u300d\uff1a\u5148\u4fdd\u5b58\uff08savefig\uff09\uff0c\u518d\u9884\u89c8\uff08show\uff09\u3002\u987a\u5e8f\u53cd\u4e86\uff0c\u9884\u89c8\u5173\u95ed\u540e\u56fe\u5c31\u6ca1\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u4fdd\u5b58\u56fe\u7247 + \u9a8c\u8bc1\u6587\u4ef6\u5b58\u5728<\/strong>\uff08\u79bb\u7ebf\u53ef\u8dd1\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport matplotlib.pyplot as plt\n\nplt.rcParams&#91;\"font.sans-serif\"] = &#91;\"SimHei\", \"Microsoft YaHei\"]\nplt.rcParams&#91;\"axes.unicode_minus\"] = False\n\nos.makedirs(\"Temp\", exist_ok=True)      # \u76ee\u5f55\u4e0d\u5b58\u5728\u5c31\u5148\u521b\u5efa\nplt.bar(&#91;\"1\u6708\", \"2\u6708\", \"3\u6708\"], &#91;120, 180, 150])\nplt.title(\"\u5b63\u5ea6\u9500\u91cf\")\nplt.savefig(\"Temp\/day25_save.png\", dpi=150)   # \u5148\u4fdd\u5b58\nprint(\"\u6587\u4ef6\u5b58\u5728\uff1a\", os.path.exists(\"Temp\/day25_save.png\"))\nprint(\"\u6587\u4ef6\u5927\u5c0f\uff08\u5b57\u8282\uff09\uff1a\", os.path.getsize(\"Temp\/day25_save.png\"))\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>os.makedirs(\"Temp\", exist_ok=True)<\/code> \u786e\u4fdd\u76ee\u5f55\u5b58\u5728\uff08\u4e0d\u5b58\u5728\u65f6 savefig \u76f4\u63a5\u62a5\u9519\uff09\uff1b<code>savefig<\/code> \u4fdd\u5b58\uff08<strong>\u6b64\u65f6\u8fd8\u6ca1\u8c03\u7528 show<\/strong>\uff09\uff1b<code>os.path.exists<\/code> \u68c0\u67e5\u6587\u4ef6\u751f\u6210\u3001<code>os.path.getsize<\/code> \u770b\u5927\u5c0f\u2014\u2014<strong>\u975e 0 \u8bf4\u660e\u4e0d\u662f\u7a7a\u767d\u56fe<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>plt.show()<\/code> \u4e4b\u540e\u518d <code>savefig()<\/code> \u2192 \u95ee\u9898\uff1a\u53ef\u80fd\u4fdd\u5b58\u5230\u7a7a\u767d\u56fe \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148 <code>savefig()<\/code> \u518d <code>show()<\/code>\uff0c\u6216\u53ea <code>savefig()<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u4fdd\u5b58\u8def\u5f84\u7684\u76ee\u5f55\u4e0d\u5b58\u5728 \u2192 \u95ee\u9898\uff1a\u62a5 <code>FileNotFoundError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148 <code>os.makedirs(\"Temp\", exist_ok=True)<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u5148\u4fdd\u5b58\u6765\u540e\u5c55\u793a\uff0cdpi \u8bb0\u5f97\u8c03\u6e05\u6670\uff1b\u76ee\u5f55\u5148\u5efa\u6587\u4ef6\u9a8c\uff0c\u975e 0 \u5927\u5c0f\u624d\u653e\u5fc3\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5 \u6807\u7b7e\u3001\u56fe\u4f8b\u4e0e\u7f51\u683c \u2014\u2014 \u8ba9\u56fe\u4f1a\u8bf4\u8bdd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u5f20\u56fe\u5149\u6709\u7ebf\u6761\u6ca1\u4eba\u770b\u5f97\u61c2\uff1a\u5f97\u544a\u8bc9\u522b\u4eba\u300c\u6a2a\u8f74\u662f\u4ec0\u4e48\u3001\u7eb5\u8f74\u662f\u4ec0\u4e48\u3001\u6bcf\u6761\u7ebf\u4ee3\u8868\u4ec0\u4e48\u300d\u3002<code>title<\/code> \/ <code>xlabel<\/code> \/ <code>ylabel<\/code> \u662f\u56fe\u7684\u4e09\u8981\u7d20\uff0c<code>legend<\/code>\uff08\u56fe\u4f8b\uff09\u6807\u6ce8\u591a\u6761\u7ebf\uff0c<code>grid<\/code>\uff08\u7f51\u683c\uff09\u65b9\u4fbf\u8bfb\u6570\u3002\u914d\u9f50\u8fd9\u4e9b\uff0c\u56fe\u8868\u624d\u4ece\u300c\u8349\u7a3f\u300d\u53d8\u6210\u300c\u4f5c\u54c1\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>plt.plot(..., label=\"\u6700\u9ad8\u6e29\")<\/code> \u91cc\u7684 <code>label<\/code> \u7ed9\u8fd9\u6761\u7ebf\u8d77\u540d\uff0c\u4f46<strong>\u540d\u5b57\u4e0d\u4f1a\u81ea\u52a8\u663e\u793a<\/strong>\u2014\u2014\u8981\u518d\u8c03 <code>plt.legend()<\/code>\uff0c\u5b83\u628a\u5f53\u524d\u5750\u6807\u7cfb\u91cc\u6240\u6709\u5e26 <code>label<\/code> \u7684\u5143\u7d20\u6536\u96c6\u8d77\u6765\u6e32\u67d3\u6210\u56fe\u4f8b\u3002<code>plt.grid(True, linestyle=\"--\", alpha=0.5)<\/code> \u753b\u523b\u5ea6\u7f51\u683c\u7ebf\uff0c<code>alpha<\/code> \u662f\u900f\u660e\u5ea6\uff080~1\uff09\uff0c\u6de1\u7f51\u683c\u4e0d\u62a2\u4e3b\u4f53\u3002\u591a\u5b50\u56fe\u65f6\u6bcf\u4e2a axes \u8981\u5355\u72ec <code>ax.legend()<\/code>\u3001<code>ax.set_xlabel()<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56fe\u4f8b\u50cf<strong>\u5730\u56fe\u53f3\u4e0b\u89d2\u7684\u56fe\u4f8b\u8bf4\u660e<\/strong>\uff1a\u6ca1\u6709\u5b83\uff0c\u522b\u4eba\u53ea\u80fd\u731c\u54ea\u6761\u7ebf\u662f\u6700\u9ad8\u6e29\uff1b\u6709\u4e86\u5b83\uff0c\u4e00\u773c\u5bf9\u53f7\u5165\u5ea7\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u53cc\u6298\u7ebf + \u56fe\u4f8b + \u7f51\u683c<\/strong>\uff08\u79bb\u7ebf\u53ef\u8dd1\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import matplotlib.pyplot as plt\n\nplt.rcParams&#91;\"font.sans-serif\"] = &#91;\"SimHei\", \"Microsoft YaHei\"]\nplt.rcParams&#91;\"axes.unicode_minus\"] = False\n\ndays = &#91;1, 2, 3, 4, 5, 6, 7]\nhigh = &#91;32, 34, 31, 29, 33, 35, 30]     # \u6700\u9ad8\u6e29\nlow = &#91;24, 25, 23, 22, 24, 26, 23]      # \u6700\u4f4e\u6e29\n\nplt.plot(days, high, marker=\"o\", label=\"\u6700\u9ad8\u6e29\")\nplt.plot(days, low, marker=\"s\", label=\"\u6700\u4f4e\u6e29\")\nplt.title(\"\u4e00\u5468\u6c14\u6e29\u8d70\u52bf\")\nplt.xlabel(\"\u65e5\u671f\uff081~7\uff09\")\nplt.ylabel(\"\u6e29\u5ea6\uff08\u2103\uff09\")\nplt.legend()                            # \u663e\u793a\u56fe\u4f8b\nplt.grid(True, linestyle=\"--\", alpha=0.5)   # \u6de1\u865a\u7ebf\u7f51\u683c\nplt.savefig(\"Temp\/day25_legend.png\", dpi=150)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e24\u6761 <code>plot<\/code> \u90fd\u52a0 <code>label<\/code> \u53c2\u6570\uff1b<code>plt.legend()<\/code> \u628a\u540d\u5b57\u6e32\u67d3\u5230\u56fe\u4f8b\u6846\uff1b<code>plt.grid(...)<\/code> \u52a0\u6de1\u865a\u7ebf\u7f51\u683c\u65b9\u4fbf\u8bfb\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u753b\u4e86\u4e24\u6761\u7ebf\u4f46\u6ca1\u5199 <code>label<\/code> \u5c31\u8c03 <code>legend()<\/code> \u2192 \u95ee\u9898\uff1a\u56fe\u4f8b\u662f\u7a7a\u6846\uff0c\u6ca1\u6709\u540d\u5b57 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u6bcf\u6761\u7ebf\u90fd\u5199 <code>label=\"...\"<\/code>\uff0c\u518d\u8c03\u4e00\u6b21 <code>legend()<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u628a <code>label<\/code> \u5199\u8fdb <code>plt.title()<\/code> \u2192 \u95ee\u9898\uff1a\u6807\u9898\u548c\u56fe\u4f8b\u6df7\u4e3a\u4e00\u8c08 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>label<\/code> \u7ed9\u7ebf\u547d\u540d\uff0c<code>title<\/code> \u7ed9\u6574\u5f20\u56fe\u547d\u540d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u6807\u9898\u8f74\u6807\u52a0\u56fe\u4f8b\uff0c\u7f51\u683c\u4e00\u5f00\u66f4\u597d\u8bfb\uff1blabel \u7ed9\u7ebf\u8d77\u540d\u5b57\uff0clegend \u8d1f\u8d23\u5c55\u793a\u5b83\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6 \u52a8\u624b\u5b9e\u8df5\uff1a\u4e00\u5468\u5b66\u4e60\u53ef\u89c6\u5316\u5206\u6790\u62a5\u544a<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u628a\u672c\u5468 7 \u5929\u3001\u6bcf\u5929 3 \u4e2a\u7ef4\u5ea6\u7684\u5b66\u4e60\u6570\u636e\u753b\u6210 4 \u5f20\u56fe\uff0c\u5e76\u751f\u6210\u4e00\u5f20\u300c\u53ef\u89c6\u5316\u5206\u6790\u62a5\u544a\u300d\u56fe\u7247\uff08\u4e00\u9875\u591a\u5b50\u56fe\uff09\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># report.py \u2014\u2014 \u4e00\u5468\u5b66\u4e60\u53ef\u89c6\u5316\u5206\u6790\u62a5\u544a\nimport matplotlib.pyplot as plt\n\nplt.rcParams&#91;\"font.sans-serif\"] = &#91;\"SimHei\", \"Microsoft YaHei\"]\nplt.rcParams&#91;\"axes.unicode_minus\"] = False\n\ndays = &#91;\"\u5468\u4e00\", \"\u5468\u4e8c\", \"\u5468\u4e09\", \"\u5468\u56db\", \"\u5468\u4e94\", \"\u5468\u516d\", \"\u5468\u65e5\"]\nhours = &#91;3, 4, 3, 2, 4, 5, 4]           # \u6bcf\u5929\u5b66\u4e60\u65f6\u957f\uff08\u5c0f\u65f6\uff09\ncode_lines = &#91;120, 200, 150, 80, 210, 320, 180]   # \u6bcf\u5929\u5199\u7684\u4ee3\u7801\u884c\u6570\nerrors = &#91;6, 4, 5, 8, 4, 2, 3]          # \u6bcf\u5929\u9047\u5230\u7684\u62a5\u9519\u6b21\u6570\nsubjects = &#91;\"\u8bed\u6cd5\u57fa\u7840\", \"\u6587\u4ef6\u4e0e\u5f02\u5e38\", \"\u9762\u5411\u5bf9\u8c61\", \"\u6570\u636e\u5206\u6790\"]\nsubject_hours = &#91;8, 10, 12, 15]         # \u5404\u4e3b\u9898\u7d2f\u8ba1\u5b66\u4e60\u65f6\u957f\n\nfig, axes = plt.subplots(2, 2, figsize=(12, 8))   # 2 \u884c 2 \u5217\u5171 4 \u4e2a\u5b50\u56fe\nfig.suptitle(\"\u4e00\u5468\u5b66\u4e60\u53ef\u89c6\u5316\u5206\u6790\u62a5\u544a\", fontsize=16)\n\n# \u5b50\u56fe1\uff1a\u6bcf\u5929\u5b66\u4e60\u65f6\u957f\u67f1\u72b6\u56fe\naxes&#91;0, 0].bar(days, hours, color=\"steelblue\")\naxes&#91;0, 0].set_title(\"\u6bcf\u5929\u5b66\u4e60\u65f6\u957f\uff08\u5c0f\u65f6\uff09\")\n\n# \u5b50\u56fe2\uff1a\u4ee3\u7801\u884c\u6570 vs \u62a5\u9519\u6b21\u6570\u6298\u7ebf\u56fe\naxes&#91;0, 1].plot(days, code_lines, marker=\"o\", label=\"\u4ee3\u7801\u884c\u6570\")\naxes&#91;0, 1].plot(days, errors, marker=\"s\", label=\"\u62a5\u9519\u6b21\u6570\")\naxes&#91;0, 1].set_title(\"\u4ee3\u7801\u91cf vs \u62a5\u9519\u6570\")\naxes&#91;0, 1].legend()\n\n# \u5b50\u56fe3\uff1a\u5b66\u4e60\u65f6\u957f\u4e0e\u62a5\u9519\u7684\u6563\u70b9\u56fe\uff08\u76f8\u5173\u5173\u7cfb\uff09\naxes&#91;1, 0].scatter(hours, errors, color=\"coral\")\naxes&#91;1, 0].set_title(\"\u5b66\u4e60\u65f6\u957f\u4e0e\u62a5\u9519\u6b21\u6570\")\naxes&#91;1, 0].set_xlabel(\"\u5b66\u4e60\u65f6\u957f\uff08\u5c0f\u65f6\uff09\")\naxes&#91;1, 0].set_ylabel(\"\u62a5\u9519\u6b21\u6570\")\n\n# \u5b50\u56fe4\uff1a\u5404\u4e3b\u9898\u65f6\u95f4\u5360\u6bd4\u997c\u56fe\naxes&#91;1, 1].pie(subject_hours, labels=subjects, autopct=\"%.1f%%\")\naxes&#91;1, 1].set_title(\"\u5404\u4e3b\u9898\u5b66\u4e60\u65f6\u95f4\u5360\u6bd4\")\n\nplt.tight_layout()          # \u81ea\u52a8\u8c03\u6574\u5b50\u56fe\u95f4\u8ddd\uff0c\u907f\u514d\u91cd\u53e0\nplt.savefig(\"week_report.png\", dpi=150)\nprint(\"\u62a5\u544a\u5df2\u4fdd\u5b58\uff1aweek_report.png\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u6548\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u62a5\u544a\u5df2\u4fdd\u5b58\uff1aweek_report.png\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6253\u5f00 <code>week_report.png<\/code>\uff0c\u80fd\u770b\u5230 2&#215;2 \u6392\u5217\u7684 4 \u5f20\u56fe\uff1a\u67f1\u72b6\u56fe\u770b\u6bcf\u5929\u65f6\u957f\u3001\u6298\u7ebf\u56fe\u5bf9\u6bd4\u4ee3\u7801\u91cf\u548c\u62a5\u9519\u3001\u6563\u70b9\u56fe\u770b\u76f8\u5173\u6027\u3001\u997c\u56fe\u770b\u4e3b\u9898\u5360\u6bd4\u3002\u8bd5\u7740\u5199\u4e00\u53e5\u5206\u6790\u7ed3\u8bba\uff0c\u6bd4\u5982\u300c\u5468\u516d\u5b66\u5f97\u6700\u591a\u4f46\u62a5\u9519\u6700\u5c11\uff0c\u8bf4\u660e\u719f\u7ec3\u5ea6\u4e0a\u6765\u4e86\u300d\u2014\u2014\u8fd9\u5c31\u662f\u4e00\u4efd\u7b80\u5355\u7684<strong>\u53ef\u89c6\u5316\u5206\u6790\u62a5\u544a<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5347\u7ea7\u6311\u6218<\/strong>\uff1a\u6362\u6210\u4f60\u81ea\u5df1\u7684\u771f\u5b9e\u6570\u636e\uff08\u7528 JSON \u6587\u4ef6\u8bfb\u6570\u636e\u518d\u753b\u56fe\uff09\uff0c\u5e76\u628a\u62a5\u544a\u4fdd\u5b58\u6210 <code>my_report.png<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4eca\u65e5\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">figure \u662f\u753b\u5e03\u3001axes \u662f\u753b\u5e03\u4e0a\u7684\u5750\u6807\u7cfb\uff1b<code>plt.subplots(1, 2)<\/code> \u8fd4\u56de\u6570\u7ec4\uff0c\u6309\u4e0b\u6807\u53d6\u5355\u4e2a\u5750\u6807\u7cfb\n\u7ed8\u56fe\u4e09\u6b65\u6cd5\uff1a\u51c6\u5907\u6570\u636e \u2192 \u9009\u56fe\u8868\u7c7b\u578b \u2192 \u8c03\u6837\u5f0f\uff1b\u6298\u7ebf\u770b\u8d8b\u52bf\u3001\u67f1\u72b6\u6bd4\u5927\u5c0f\u3001\u6563\u70b9\u627e\u76f8\u5173\u3001\u997c\u56fe\u770b\u5360\u6bd4\uff0c\u9009\u56fe\u4e0d\u7ea0\u7ed3\n\u6bcf\u5f20\u56fe\u90fd\u914d\u597d\u6807\u9898\u3001\u8f74\u6807\u7b7e\uff0c\u9700\u8981\u533a\u5206\u591a\u6761\u7ebf\u65f6\u52a0\u56fe\u4f8b\uff08label + legend\uff09\uff0c\u6de1\u7f51\u683c\u65b9\u4fbf\u8bfb\u6570\n\u4e2d\u6587\u663e\u793a\u4e24\u4ef6\u5957\uff1a<code>font.sans-serif<\/code> \u6307\u5b9a\u7cfb\u7edf\u4e2d\u6587\u5b57\u4f53 + <code>axes.unicode_minus = False<\/code>\uff1b\u5b57\u4f53\u540d\u968f\u7cfb\u7edf\u53d8\n\u4fdd\u5b58\u56fe\u7247\uff1a\u5148 <code>savefig()<\/code> \u518d <code>show()<\/code>\uff1b<code>dpi=150~300<\/code>\uff1b\u76ee\u5f55\u5148\u5efa\u3001\u6587\u4ef6\u7528 <code>os.path.exists<\/code> \u9a8c\u8bc1\n\u5b8c\u6210\u300c\u4e00\u5468\u5b66\u4e60\u53ef\u89c6\u5316\u5206\u6790\u62a5\u544a\u300d\uff1a\u4e00\u9875 4 \u5b50\u56fe\uff082&#215;2\uff09\uff0c\u5e76\u5199\u51fa\u4e00\u53e5\u5206\u6790\u7ed3\u8bba<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u62a5\u9519<\/th><th>\u539f\u56e0<\/th><th>\u4fee\u590d<\/th><\/tr><\/thead><tbody><tr><td><code>ModuleNotFoundError: No module named 'matplotlib'<\/code><\/td><td>\u6ca1\u5b89\u88c5 matplotlib<\/td><td>\u547d\u4ee4\u884c\u6267\u884c <code>pip install matplotlib<\/code><\/td><\/tr><tr><td>\u56fe\u91cc\u7684\u4e2d\u6587\u5168\u662f\u65b9\u6846\uff08\u25a1\uff09<\/td><td>\u9ed8\u8ba4\u5b57\u4f53\u4e0d\u542b\u4e2d\u6587\u5b57\u5f62<\/td><td>\u811a\u672c\u5f00\u5934\u52a0 <code>plt.rcParams[\"font.sans-serif\"] = [\"SimHei\", \"Microsoft YaHei\"]<\/code><\/td><\/tr><tr><td><code>ValueError: x and y must have same first dimension<\/code><\/td><td>x \u548c y \u957f\u5ea6\u4e0d\u4e00\u81f4<\/td><td>\u68c0\u67e5\u4e24\u4e2a\u5217\u8868\u5143\u7d20\u4e2a\u6570\u662f\u5426\u76f8\u7b49<\/td><\/tr><tr><td>\u4fdd\u5b58\u51fa\u6765\u7684\u56fe\u7247\u662f\u7a7a\u767d<\/td><td><code>show()<\/code> \u4e4b\u540e\u624d <code>savefig()<\/code>\uff0c\u7a97\u53e3\u5df2\u5173\u95ed\u753b\u5e03\u88ab\u6e05\u7a7a<\/td><td>\u5148 <code>savefig()<\/code> \u518d <code>show()<\/code>\uff0c\u6216\u53ea\u8c03\u7528 <code>savefig()<\/code><\/td><\/tr><tr><td><code>AttributeError: 'numpy.ndarray' object has no attribute 'plot'<\/code><\/td><td><code>plt.subplots(2, 2)<\/code> \u8fd4\u56de\u7684\u662f 2&#215;2 \u7684\u6570\u7ec4\uff0c\u4e0d\u80fd\u76f4\u63a5 <code>.plot()<\/code><\/td><td>\u7528 <code>axes[0, 0].plot(...)<\/code> \u6307\u5b9a\u5b50\u56fe\uff0c\u4e0d\u8981\u5199 <code>axes.plot(...)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1 figure \u4e0e axes \u2014\u2014 \u753b\u5e03\u4e0e\u5750\u6807\u7cfb \u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f figure\uff08\u753b\u5e03\uff09\u662f\u6574\u5f20\u56fe\uff0caxes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[16,9],"tags":[17],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-python","category-code-dev","tag-python-day"],"_links":{"self":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":2,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":154,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions\/154"}],"wp:attachment":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}