{"id":932338,"date":"2024-12-26T17:56:22","date_gmt":"2024-12-26T09:56:22","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/932338.html"},"modified":"2024-12-26T17:56:24","modified_gmt":"2024-12-26T09:56:24","slug":"python-plt%e5%a6%82%e4%bd%95%e7%94%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/932338.html","title":{"rendered":"python plt\u5982\u4f55\u7528"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25070221\/598a374c-49c5-473e-afad-52a5f2bb37ba.webp\" alt=\"python plt\u5982\u4f55\u7528\" \/><\/p>\n<p><p> \u4e00\u3001PYTHON PLT\u5982\u4f55\u7528<\/p>\n<\/p>\n<p><p><strong>Python\u7684plt\u5e93\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u3001\u521b\u5efa\u56fe\u8868\u3001\u652f\u6301\u591a\u79cd\u56fe\u5f62\u683c\u5f0f<\/strong>\u3002\u5b83\u662fmatplotlib\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u800c\u5f3a\u5927\u7684\u65b9\u5f0f\u6765\u751f\u6210\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5982\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u6563\u70b9\u56fe\u7b49\u3002\u4f7f\u7528plt\u5e93\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u7406\u89e3\u548c\u5c55\u793a\u6570\u636e\u3002\u5728\u4f7f\u7528plt\u5e93\u4e4b\u524d\uff0c\u901a\u5e38\u9700\u8981\u5148\u5bfc\u5165matplotlib.pyplot\u6a21\u5757\u3002\u6b64\u6a21\u5757\u63d0\u4f9b\u4e86\u8bb8\u591a\u7528\u4e8e\u7ed8\u56fe\u7684\u51fd\u6570\u548c\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165\u5e93\uff0c\u7136\u540e\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684\u51fd\u6570\u8c03\u7528\u6765\u521b\u5efa\u548c\u5c55\u793a\u56fe\u5f62\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528plt\u5e93\u6765\u521b\u5efa\u4e0d\u540c\u7c7b\u578b\u7684\u56fe\u8868\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5b89\u88c5\u4e0e\u5bfc\u5165<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4f7f\u7528plt\u4e4b\u524d\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u786e\u4fddmatplotlib\u5e93\u5df2\u7ecf\u5b89\u88c5\u5728\u6211\u4eec\u7684Python\u73af\u5883\u4e2d\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728\u60a8\u7684Python\u811a\u672c\u4e2d\u5bfc\u5165pyplot\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528plt\u63d0\u4f9b\u7684\u5404\u79cd\u529f\u80fd\u6765\u521b\u5efa\u56fe\u8868\u4e86\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u7ed8\u5236\u7b80\u5355\u7684\u56fe\u5f62<\/p>\n<\/p>\n<ol>\n<li><strong>\u7ed8\u5236\u6298\u7ebf\u56fe<\/strong><\/li>\n<\/ol>\n<p><p>\u6298\u7ebf\u56fe\u662fplt\u4e2d\u6700\u57fa\u672c\u7684\u56fe\u5f62\u4e4b\u4e00\uff0c\u5b83\u53ef\u4ee5\u7528\u4e8e\u5c55\u793a\u6570\u636e\u968f\u65f6\u95f4\u6216\u5176\u4ed6\u53d8\u91cf\u53d8\u5316\u7684\u8d8b\u52bf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6298\u7ebf\u56fe\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u6570\u636e<\/strong><\/h2>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [2, 3, 5, 7, 11]<\/p>\n<h2><strong>\u7ed8\u5236\u6298\u7ebf\u56fe<\/strong><\/h2>\n<p>plt.plot(x, y)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898\u548c\u6807\u7b7e<\/strong><\/h2>\n<p>plt.title(&quot;Simple Line Plot&quot;)<\/p>\n<p>plt.xlabel(&quot;X Axis&quot;)<\/p>\n<p>plt.ylabel(&quot;Y Axis&quot;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u7ed8\u5236\u6563\u70b9\u56fe<\/strong><\/li>\n<\/ol>\n<p><p>\u6563\u70b9\u56fe\u7528\u4e8e\u5c55\u793a\u4e24\u7ec4\u6570\u636e\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>plt.scatter()<\/code>\u51fd\u6570\u6765\u521b\u5efa\u6563\u70b9\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u6570\u636e<\/strong><\/h2>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [5, 7, 9, 11, 13]<\/p>\n<h2><strong>\u7ed8\u5236\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>plt.scatter(x, y)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898\u548c\u6807\u7b7e<\/strong><\/h2>\n<p>plt.title(&quot;Simple Scatter Plot&quot;)<\/p>\n<p>plt.xlabel(&quot;X Axis&quot;)<\/p>\n<p>plt.ylabel(&quot;Y Axis&quot;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u5b9a\u5236\u56fe\u5f62\u5916\u89c2<\/p>\n<\/p>\n<ol>\n<li><strong>\u8bbe\u7f6e\u7ebf\u6761\u6837\u5f0f<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u7ed8\u5236\u6298\u7ebf\u56fe\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u8bbe\u7f6e\u7ebf\u6761\u7684\u989c\u8272\u3001\u6837\u5f0f\u548c\u5bbd\u5ea6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y, color=&#39;green&#39;, linestyle=&#39;--&#39;, linewidth=2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6dfb\u52a0\u7f51\u683c<\/strong><\/li>\n<\/ol>\n<p><p>\u7f51\u683c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u8bfb\u53d6\u56fe\u5f62\u4e2d\u7684\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>plt.grid()<\/code>\u51fd\u6570\u6765\u6dfb\u52a0\u7f51\u683c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.grid(True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u8bbe\u7f6e\u56fe\u4f8b<\/strong><\/li>\n<\/ol>\n<p><p>\u5982\u679c\u6211\u4eec\u5728\u4e00\u5f20\u56fe\u4e2d\u7ed8\u5236\u591a\u6761\u7ebf\u6216\u591a\u4e2a\u6570\u636e\u96c6\uff0c\u56fe\u4f8b\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u533a\u5206\u4e0d\u540c\u7684\u6570\u636e\u3002\u53ef\u4ee5\u4f7f\u7528<code>plt.legend()<\/code>\u51fd\u6570\u6765\u6dfb\u52a0\u56fe\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot(x, y, label=&#39;Line 1&#39;)<\/p>\n<p>plt.plot(x, [10, 15, 20, 25, 30], label=&#39;Line 2&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u7ed8\u5236\u5176\u4ed6\u7c7b\u578b\u7684\u56fe\u8868<\/p>\n<\/p>\n<ol>\n<li><strong>\u67f1\u72b6\u56fe<\/strong><\/li>\n<\/ol>\n<p><p>\u67f1\u72b6\u56fe\u7528\u4e8e\u5bf9\u6bd4\u4e0d\u540c\u7c7b\u522b\u7684\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>plt.bar()<\/code>\u51fd\u6570\u6765\u521b\u5efa\u67f1\u72b6\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u6570\u636e<\/strong><\/h2>\n<p>categories = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;]<\/p>\n<p>values = [4, 7, 1, 8]<\/p>\n<h2><strong>\u7ed8\u5236\u67f1\u72b6\u56fe<\/strong><\/h2>\n<p>plt.bar(categories, values)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898\u548c\u6807\u7b7e<\/strong><\/h2>\n<p>plt.title(&quot;Simple Bar Chart&quot;)<\/p>\n<p>plt.xlabel(&quot;Categories&quot;)<\/p>\n<p>plt.ylabel(&quot;Values&quot;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u997c\u56fe<\/strong><\/li>\n<\/ol>\n<p><p>\u997c\u56fe\u7528\u4e8e\u5c55\u793a\u5404\u90e8\u5206\u5728\u6574\u4f53\u4e2d\u7684\u6bd4\u4f8b\u3002\u53ef\u4ee5\u4f7f\u7528<code>plt.pie()<\/code>\u51fd\u6570\u6765\u521b\u5efa\u997c\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u6570\u636e<\/strong><\/h2>\n<p>sizes = [15, 30, 45, 10]<\/p>\n<p>labels = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;]<\/p>\n<h2><strong>\u7ed8\u5236\u997c\u56fe<\/strong><\/h2>\n<p>plt.pie(sizes, labels=labels, autopct=&#39;%1.1f%%&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898<\/strong><\/h2>\n<p>plt.title(&quot;Simple Pie Chart&quot;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u4fdd\u5b58\u56fe\u5f62<\/p>\n<\/p>\n<p><p>\u5728\u5b8c\u6210\u56fe\u5f62\u7684\u521b\u5efa\u548c\u5b9a\u5236\u540e\uff0c\u6211\u4eec\u53ef\u80fd\u5e0c\u671b\u5c06\u56fe\u5f62\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6\u3002plt\u63d0\u4f9b\u4e86<code>plt.savefig()<\/code>\u51fd\u6570\u7528\u4e8e\u4fdd\u5b58\u56fe\u5f62\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.savefig(&#39;my_plot.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u6307\u5b9a\u4fdd\u5b58\u7684\u6587\u4ef6\u683c\u5f0f\uff0c\u5982PNG\u3001JPG\u3001SVG\u7b49\uff0c\u53ea\u9700\u6539\u53d8\u6587\u4ef6\u6269\u5c55\u540d\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u5b50\u56fe\u4e0e\u591a\u56fe\u5904\u7406<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u5b50\u56fe<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u4e00\u4e2a\u56fe\u5f62\u7a97\u53e3\u4e2d\u663e\u793a\u591a\u4e2a\u5b50\u56fe\uff0c\u53ef\u4ee5\u4f7f\u7528<code>plt.subplot()<\/code>\u51fd\u6570\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e24\u884c\u4e24\u5217\u7684\u5b50\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.subplot(2, 2, 1)  # \u521b\u5efa\u7b2c\u4e00\u4e2a\u5b50\u56fe<\/p>\n<p>plt.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>plt.subplot(2, 2, 2)  # \u521b\u5efa\u7b2c\u4e8c\u4e2a\u5b50\u56fe<\/p>\n<p>plt.plot([1, 2, 3], [7, 8, 9])<\/p>\n<p>plt.subplot(2, 2, 3)  # \u521b\u5efa\u7b2c\u4e09\u4e2a\u5b50\u56fe<\/p>\n<p>plt.plot([1, 2, 3], [10, 11, 12])<\/p>\n<p>plt.subplot(2, 2, 4)  # \u521b\u5efa\u7b2c\u56db\u4e2a\u5b50\u56fe<\/p>\n<p>plt.plot([1, 2, 3], [13, 14, 15])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u591a\u56fe\u663e\u793a<\/strong><\/li>\n<\/ol>\n<p><p>\u6709\u65f6\u6211\u4eec\u5e0c\u671b\u5728\u591a\u4e2a\u56fe\u5f62\u7a97\u53e3\u4e2d\u663e\u793a\u56fe\u5f62\uff0c\u53ef\u4ee5\u4f7f\u7528<code>plt.figure()<\/code>\u6765\u521b\u5efa\u65b0\u56fe\u5f62\u7a97\u53e3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(1)<\/p>\n<p>plt.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>plt.title(&quot;Figure 1&quot;)<\/p>\n<p>plt.figure(2)<\/p>\n<p>plt.plot([1, 2, 3], [7, 8, 9])<\/p>\n<p>plt.title(&quot;Figure 2&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516b\u3001\u7ed3\u8bba<\/p>\n<\/p>\n<p><p>Python\u7684plt\u5e93\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4ee5\u56fe\u5f62\u5316\u7684\u65b9\u5f0f\u5c55\u793a\u548c\u5206\u6790\u6570\u636e\u3002\u901a\u8fc7\u5b66\u4e60\u5982\u4f55\u4f7f\u7528plt\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u5404\u79cd\u56fe\u8868\uff0c\u5e76\u6839\u636e\u9700\u8981\u8fdb\u884c\u5b9a\u5236\uff0c\u4ece\u800c\u66f4\u597d\u5730\u7406\u89e3\u548c\u5448\u73b0\u6570\u636e\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u6298\u7ebf\u56fe\u8fd8\u662f\u590d\u6742\u7684\u591a\u56fe\u5e03\u5c40\uff0cplt\u90fd\u80fd\u63d0\u4f9b\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u6c42\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u638c\u63e1plt\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5e76\u5728\u6570\u636e\u53ef\u89c6\u5316\u4e2d\u5e94\u7528\u81ea\u5982\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528plt\u6a21\u5757\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0cplt\u901a\u5e38\u662f\u6307Matplotlib\u5e93\u4e2d\u7684pyplot\u6a21\u5757\u3002\u4f7f\u7528plt\u53ef\u4ee5\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5982\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u6563\u70b9\u56fe\u7b49\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88c5Matplotlib\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\uff1a<code>pip install matplotlib<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>import matplotlib.pyplot as plt<\/code>\u5bfc\u5165\u8be5\u6a21\u5757\u3002\u63a5\u4e0b\u6765\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528plt\u63d0\u4f9b\u7684\u51fd\u6570\u6765\u751f\u6210\u56fe\u8868\uff0c\u4f8b\u5982<code>plt.plot()<\/code>\u7528\u4e8e\u7ed8\u5236\u6298\u7ebf\u56fe\uff0c<code>plt.bar()<\/code>\u7528\u4e8e\u7ed8\u5236\u67f1\u72b6\u56fe\uff0c<code>plt.scatter()<\/code>\u7528\u4e8e\u7ed8\u5236\u6563\u70b9\u56fe\u3002\u5b8c\u6210\u56fe\u8868\u7684\u7ed8\u5236\u540e\uff0c\u4f7f\u7528<code>plt.show()<\/code>\u6765\u663e\u793a\u56fe\u8868\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728plt\u4e2d\u81ea\u5b9a\u4e49\u56fe\u8868\u7684\u6837\u5f0f\u548c\u6807\u7b7e\uff1f<\/strong><br \/>\u5728\u4f7f\u7528plt\u7ed8\u5236\u56fe\u8868\u65f6\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u81ea\u5b9a\u4e49\u56fe\u8868\u7684\u6837\u5f0f\u548c\u6807\u7b7e\u3002\u4f7f\u7528<code>plt.title()<\/code>\u8bbe\u7f6e\u56fe\u8868\u6807\u9898\uff0c<code>plt.xlabel()<\/code>\u548c<code>plt.ylabel()<\/code>\u53ef\u4ee5\u5206\u522b\u6dfb\u52a0x\u8f74\u548cy\u8f74\u7684\u6807\u7b7e\u3002\u5982\u679c\u9700\u8981\u66f4\u6539\u56fe\u8868\u7684\u989c\u8272\u3001\u7ebf\u578b\u6216\u6807\u8bb0\u6837\u5f0f\uff0c\u53ef\u4ee5\u5728\u8c03\u7528\u7ed8\u56fe\u51fd\u6570\u65f6\u4f20\u9012\u76f8\u5173\u53c2\u6570\uff0c\u5982<code>plt.plot(x, y, color=&#39;red&#39;, linestyle=&#39;--&#39;)<\/code>\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528<code>plt.legend()<\/code>\u6dfb\u52a0\u56fe\u4f8b\uff0c\u4f7f\u56fe\u8868\u66f4\u5177\u53ef\u8bfb\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u4fdd\u5b58\u4f7f\u7528plt\u7ed8\u5236\u7684\u56fe\u8868\u4e3a\u6587\u4ef6\uff1f<\/strong><br \/>\u5728\u4f7f\u7528plt\u5b8c\u6210\u56fe\u8868\u7684\u7ed8\u5236\u540e\uff0c\u60a8\u53ef\u4ee5\u5c06\u56fe\u8868\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6\u3002\u4f7f\u7528<code>plt.savefig(&#39;filename.png&#39;)<\/code>\u53ef\u4ee5\u5c06\u56fe\u8868\u4fdd\u5b58\u4e3aPNG\u683c\u5f0f\u3002\u60a8\u8fd8\u53ef\u4ee5\u6307\u5b9a\u5176\u4ed6\u683c\u5f0f\uff0c\u5982JPEG\u6216PDF\uff0c\u53ea\u9700\u66f4\u6539\u6587\u4ef6\u6269\u5c55\u540d\u5373\u53ef\u3002\u5728\u4fdd\u5b58\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u8bbe\u7f6e\u56fe\u50cf\u7684\u5206\u8fa8\u7387\uff0c\u6bd4\u5982<code>plt.savefig(&#39;filename.png&#39;, dpi=300)<\/code>\u3002\u8fd9\u6709\u52a9\u4e8e\u751f\u6210\u9ad8\u8d28\u91cf\u7684\u56fe\u50cf\uff0c\u9002\u5408\u6253\u5370\u6216\u53d1\u8868\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001PYTHON PLT\u5982\u4f55\u7528 Python\u7684plt\u5e93\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u3001\u521b\u5efa\u56fe\u8868\u3001\u652f\u6301\u591a\u79cd\u56fe\u5f62\u683c\u5f0f\u3002\u5b83\u662fmatp [&hellip;]","protected":false},"author":3,"featured_media":932340,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/932338"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=932338"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/932338\/revisions"}],"predecessor-version":[{"id":932342,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/932338\/revisions\/932342"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/932340"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=932338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=932338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=932338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}