{"id":1105484,"date":"2025-01-08T16:31:20","date_gmt":"2025-01-08T08:31:20","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1105484.html"},"modified":"2025-01-08T16:31:24","modified_gmt":"2025-01-08T08:31:24","slug":"python%e5%a6%82%e4%bd%95%e6%8a%8a%e5%a4%9a%e6%9d%a1%e6%9b%b2%e7%ba%bf%e5%81%9a%e5%88%b0%e4%b8%80%e8%b5%b7","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1105484.html","title":{"rendered":"python\u5982\u4f55\u628a\u591a\u6761\u66f2\u7ebf\u505a\u5230\u4e00\u8d77"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25070351\/2752cf4e-4aed-4024-8e95-a0ce93bfa687.webp\" alt=\"python\u5982\u4f55\u628a\u591a\u6761\u66f2\u7ebf\u505a\u5230\u4e00\u8d77\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5c06\u591a\u6761\u66f2\u7ebf\u7ed8\u5236\u5230\u4e00\u8d77\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u901a\u5e38\u4f7f\u7528\u7684\u5e93\u662fMatplotlib\u3002\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528plot\u51fd\u6570\u3001\u4f7f\u7528\u5faa\u73af\u7ed8\u5236\u591a\u6761\u66f2\u7ebf\u3001\u4f7f\u7528\u4e0d\u540c\u7684\u989c\u8272\u548c\u6837\u5f0f\u533a\u5206\u66f2\u7ebf\u7b49\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\uff0c\u5373\u4f7f\u7528Matplotlib\u5e93\u7684plot\u51fd\u6570\u7ed8\u5236\u591a\u6761\u66f2\u7ebf\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u548c\u5bfc\u5165Matplotlib\u5e93<\/h3>\n<\/p>\n<p><p>\u8981\u4f7f\u7528Matplotlib\u5e93\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86\u8be5\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\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\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u8be5\u5e93\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><h3>\u4e8c\u3001\u4f7f\u7528plot\u51fd\u6570\u7ed8\u5236\u591a\u6761\u66f2\u7ebf<\/h3>\n<\/p>\n<p><p>Matplotlib\u7684plot\u51fd\u6570\u662f\u7ed8\u5236\u66f2\u7ebf\u7684\u4e3b\u8981\u5de5\u5177\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u591a\u6b21\u8c03\u7528plot\u51fd\u6570\uff0c\u5c06\u591a\u6761\u66f2\u7ebf\u7ed8\u5236\u5728\u540c\u4e00\u5f20\u56fe\u4e0a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y1 = np.sin(x)<\/p>\n<p>y2 = np.cos(x)<\/p>\n<p>y3 = np.tan(x)<\/p>\n<h2><strong>\u7ed8\u5236\u591a\u6761\u66f2\u7ebf<\/strong><\/h2>\n<p>plt.plot(x, y1, label=&#39;sin(x)&#39;)<\/p>\n<p>plt.plot(x, y2, label=&#39;cos(x)&#39;)<\/p>\n<p>plt.plot(x, y3, label=&#39;tan(x)&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b<\/strong><\/h2>\n<p>plt.legend()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u751f\u6210\u4e86\u4e00\u4e9b\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528plot\u51fd\u6570\u7ed8\u5236\u4e86\u4e09\u6761\u66f2\u7ebf\uff1asin(x)\u3001cos(x)\u548ctan(x)\u3002\u901a\u8fc7\u4f20\u9012label\u53c2\u6570\uff0c\u6211\u4eec\u4e3a\u6bcf\u6761\u66f2\u7ebf\u6dfb\u52a0\u4e86\u6807\u7b7e\uff0c\u8fd9\u6837\u53ef\u4ee5\u5728\u56fe\u4f8b\u4e2d\u663e\u793a\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5faa\u73af\u7ed8\u5236\u591a\u6761\u66f2\u7ebf<\/h3>\n<\/p>\n<p><p>\u5f53\u9700\u8981\u7ed8\u5236\u5927\u91cf\u66f2\u7ebf\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u7b80\u5316\u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u5faa\u73af\u7ed8\u5236\u591a\u6761\u66f2\u7ebf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>functions = [np.sin, np.cos, np.tan]<\/p>\n<p>labels = [&#39;sin(x)&#39;, &#39;cos(x)&#39;, &#39;tan(x)&#39;]<\/p>\n<h2><strong>\u4f7f\u7528\u5faa\u73af\u7ed8\u5236\u591a\u6761\u66f2\u7ebf<\/strong><\/h2>\n<p>for func, label in zip(functions, labels):<\/p>\n<p>    y = func(x)<\/p>\n<p>    plt.plot(x, y, label=label)<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b<\/strong><\/h2>\n<p>plt.legend()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u51fd\u6570\u548c\u6807\u7b7e\u5b58\u50a8\u5728\u5217\u8868\u4e2d\uff0c\u7136\u540e\u4f7f\u7528\u5faa\u73af\u904d\u5386\u8fd9\u4e9b\u5217\u8868\uff0c\u8c03\u7528plot\u51fd\u6570\u7ed8\u5236\u6bcf\u6761\u66f2\u7ebf\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u4e0d\u540c\u7684\u989c\u8272\u548c\u6837\u5f0f\u533a\u5206\u66f2\u7ebf<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u533a\u5206\u591a\u6761\u66f2\u7ebf\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u989c\u8272\u548c\u6837\u5f0f\u3002Matplotlib\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6837\u5f0f\u9009\u9879\uff0c\u5982\u7ebf\u578b\u3001\u989c\u8272\u548c\u6807\u8bb0\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y1 = np.sin(x)<\/p>\n<p>y2 = np.cos(x)<\/p>\n<p>y3 = np.tan(x)<\/p>\n<h2><strong>\u4f7f\u7528\u4e0d\u540c\u7684\u989c\u8272\u548c\u6837\u5f0f\u7ed8\u5236\u591a\u6761\u66f2\u7ebf<\/strong><\/h2>\n<p>plt.plot(x, y1, &#39;r-&#39;, label=&#39;sin(x)&#39;)  # \u7ea2\u8272\u5b9e\u7ebf<\/p>\n<p>plt.plot(x, y2, &#39;g--&#39;, label=&#39;cos(x)&#39;) # \u7eff\u8272\u865a\u7ebf<\/p>\n<p>plt.plot(x, y3, &#39;b:&#39;, label=&#39;tan(x)&#39;)  # \u84dd\u8272\u70b9\u7ebf<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b<\/strong><\/h2>\n<p>plt.legend()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u4f20\u9012\u989c\u8272\u548c\u6837\u5f0f\u53c2\u6570\uff08\u5982&#39;r-&#39;, &#39;g&#8211;&#39;, &#39;b:&#39;\uff09\u7ed9plot\u51fd\u6570\uff0c\u5206\u522b\u4f7f\u7528\u7ea2\u8272\u5b9e\u7ebf\u3001\u7eff\u8272\u865a\u7ebf\u548c\u84dd\u8272\u70b9\u7ebf\u7ed8\u5236\u4e09\u6761\u66f2\u7ebf\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6dfb\u52a0\u6807\u9898\u3001\u8f74\u6807\u7b7e\u548c\u7f51\u683c<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u56fe\u5f62\u66f4\u52a0\u6e05\u6670\u548c\u4e13\u4e1a\uff0c\u53ef\u4ee5\u6dfb\u52a0\u6807\u9898\u3001\u8f74\u6807\u7b7e\u548c\u7f51\u683c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y1 = np.sin(x)<\/p>\n<p>y2 = np.cos(x)<\/p>\n<p>y3 = np.tan(x)<\/p>\n<h2><strong>\u7ed8\u5236\u591a\u6761\u66f2\u7ebf<\/strong><\/h2>\n<p>plt.plot(x, y1, &#39;r-&#39;, label=&#39;sin(x)&#39;)<\/p>\n<p>plt.plot(x, y2, &#39;g--&#39;, label=&#39;cos(x)&#39;)<\/p>\n<p>plt.plot(x, y3, &#39;b:&#39;, label=&#39;tan(x)&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898\u548c\u8f74\u6807\u7b7e<\/strong><\/h2>\n<p>plt.title(&#39;Trigonometric Functions&#39;)<\/p>\n<p>plt.xlabel(&#39;x&#39;)<\/p>\n<p>plt.ylabel(&#39;y&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u7f51\u683c<\/strong><\/h2>\n<p>plt.grid(True)<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b<\/strong><\/h2>\n<p>plt.legend()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528title\u3001xlabel\u548cylabel\u51fd\u6570\u5206\u522b\u6dfb\u52a0\u4e86\u6807\u9898\u548c\u8f74\u6807\u7b7e\uff0c\u4f7f\u7528grid\u51fd\u6570\u6dfb\u52a0\u4e86\u7f51\u683c\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4fdd\u5b58\u56fe\u5f62\u5230\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5c06\u7ed8\u5236\u7684\u56fe\u5f62\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u4f8b\u5982\u4fdd\u5b58\u4e3aPNG\u6216PDF\u683c\u5f0f\u3002\u53ef\u4ee5\u4f7f\u7528savefig\u51fd\u6570\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y1 = np.sin(x)<\/p>\n<p>y2 = np.cos(x)<\/p>\n<p>y3 = np.tan(x)<\/p>\n<h2><strong>\u7ed8\u5236\u591a\u6761\u66f2\u7ebf<\/strong><\/h2>\n<p>plt.plot(x, y1, &#39;r-&#39;, label=&#39;sin(x)&#39;)<\/p>\n<p>plt.plot(x, y2, &#39;g--&#39;, label=&#39;cos(x)&#39;)<\/p>\n<p>plt.plot(x, y3, &#39;b:&#39;, label=&#39;tan(x)&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898\u548c\u8f74\u6807\u7b7e<\/strong><\/h2>\n<p>plt.title(&#39;Trigonometric Functions&#39;)<\/p>\n<p>plt.xlabel(&#39;x&#39;)<\/p>\n<p>plt.ylabel(&#39;y&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u7f51\u683c<\/strong><\/h2>\n<p>plt.grid(True)<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b<\/strong><\/h2>\n<p>plt.legend()<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u5f62\u5230\u6587\u4ef6<\/strong><\/h2>\n<p>plt.savefig(&#39;trigonometric_functions.png&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528savefig\u51fd\u6570\u5c06\u56fe\u5f62\u4fdd\u5b58\u4e3aPNG\u6587\u4ef6\u3002\u53ef\u4ee5\u6839\u636e\u9700\u8981\u66f4\u6539\u6587\u4ef6\u540d\u548c\u683c\u5f0f\uff0c\u5982&#39;savefig(&#39;trigonometric_functions.pdf&#39;)&#39;\u5c06\u56fe\u5f62\u4fdd\u5b58\u4e3aPDF\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u7528\u5b50\u56fe\u7ed8\u5236\u591a\u6761\u66f2\u7ebf<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5728\u540c\u4e00\u5f20\u56fe\u4e2d\u7ed8\u5236\u591a\u4e2a\u5b50\u56fe\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u6bd4\u8f83\u4e0d\u540c\u7684\u6570\u636e\u96c6\u3002\u53ef\u4ee5\u4f7f\u7528subplot\u51fd\u6570\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y1 = np.sin(x)<\/p>\n<p>y2 = np.cos(x)<\/p>\n<p>y3 = np.tan(x)<\/p>\n<h2><strong>\u521b\u5efa\u5b50\u56fe<\/strong><\/h2>\n<p>fig, axs = plt.subplots(3, 1, figsize=(6, 8))<\/p>\n<h2><strong>\u7ed8\u5236\u7b2c\u4e00\u6761\u66f2\u7ebf<\/strong><\/h2>\n<p>axs[0].plot(x, y1, &#39;r-&#39;)<\/p>\n<p>axs[0].set_title(&#39;sin(x)&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u7b2c\u4e8c\u6761\u66f2\u7ebf<\/strong><\/h2>\n<p>axs[1].plot(x, y2, &#39;g--&#39;)<\/p>\n<p>axs[1].set_title(&#39;cos(x)&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u7b2c\u4e09\u6761\u66f2\u7ebf<\/strong><\/h2>\n<p>axs[2].plot(x, y3, &#39;b:&#39;)<\/p>\n<p>axs[2].set_title(&#39;tan(x)&#39;)<\/p>\n<h2><strong>\u8c03\u6574\u5b50\u56fe\u5e03\u5c40<\/strong><\/h2>\n<p>plt.tight_layout()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528subplots\u51fd\u6570\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62\uff0c\u5e76\u5728\u6bcf\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u4e86\u4e00\u6761\u66f2\u7ebf\u3002\u901a\u8fc7\u8c03\u7528tight_layout\u51fd\u6570\uff0c\u53ef\u4ee5\u81ea\u52a8\u8c03\u6574\u5b50\u56fe\u5e03\u5c40\uff0c\u4f7f\u5176\u66f4\u7d27\u51d1\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u4f7f\u7528Matplotlib\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u591a\u6761\u66f2\u7ebf\u7ed8\u5236\u5230\u4e00\u8d77\u3002\u901a\u8fc7\u8c03\u7528plot\u51fd\u6570\u3001\u4f7f\u7528\u5faa\u73af\u3001\u8bbe\u7f6e\u4e0d\u540c\u7684\u989c\u8272\u548c\u6837\u5f0f\u3001\u6dfb\u52a0\u6807\u9898\u548c\u8f74\u6807\u7b7e\u3001\u4fdd\u5b58\u56fe\u5f62\u5230\u6587\u4ef6\u4ee5\u53ca\u4f7f\u7528\u5b50\u56fe\u7b49\u65b9\u6cd5\uff0c\u53ef\u4ee5\u521b\u5efa\u4e13\u4e1a\u7684\u56fe\u5f62\u3002\u5e0c\u671b\u672c\u6587\u7684\u4ecb\u7ecd\u80fd\u591f\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u638c\u63e1\u5728Python\u4e2d\u7ed8\u5236\u591a\u6761\u66f2\u7ebf\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u591a\u6761\u66f2\u7ebf\u7ed8\u5236\u5728\u540c\u4e00\u56fe\u8868\u4e0a\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u7ed8\u5236\u591a\u6761\u66f2\u7ebf\u3002\u4f60\u53ea\u9700\u5728\u540c\u4e00\u5750\u6807\u8f74\u4e0a\u591a\u6b21\u8c03\u7528\u7ed8\u56fe\u51fd\u6570\uff0c\u4f8b\u5982<code>plt.plot()<\/code>\uff0c\u5e76\u4e3a\u6bcf\u6761\u66f2\u7ebf\u8bbe\u7f6e\u4e0d\u540c\u7684\u989c\u8272\u6216\u6837\u5f0f\uff0c\u4ee5\u4fbf\u4e8e\u533a\u5206\u3002<\/p>\n<p><strong>\u5728\u7ed8\u5236\u591a\u6761\u66f2\u7ebf\u65f6\uff0c\u5982\u4f55\u8bbe\u7f6e\u56fe\u4f8b\u4ee5\u4fbf\u66f4\u597d\u5730\u7406\u89e3\u6bcf\u6761\u66f2\u7ebf\uff1f<\/strong><br \/>\u901a\u8fc7\u4f7f\u7528<code>plt.legend()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u4e3a\u6bcf\u6761\u66f2\u7ebf\u6dfb\u52a0\u56fe\u4f8b\u3002\u5728\u8c03\u7528<code>plt.plot()<\/code>\u65f6\uff0c\u4f20\u9012\u4e00\u4e2a\u6807\u7b7e\u53c2\u6570\uff0c\u7136\u540e\u5728\u6700\u540e\u8c03\u7528<code>plt.legend()<\/code>\u5373\u53ef\u663e\u793a\u56fe\u4f8b\u3002\u8fd9\u80fd\u5e2e\u52a9\u89c2\u4f17\u66f4\u5bb9\u6613\u7406\u89e3\u56fe\u8868\u4e2d\u6bcf\u6761\u7ebf\u7684\u4ee3\u8868\u542b\u4e49\u3002<\/p>\n<p><strong>\u5982\u4f55\u8c03\u6574\u5750\u6807\u8f74\u7684\u8303\u56f4\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u663e\u793a\u591a\u6761\u66f2\u7ebf\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>plt.xlim()<\/code>\u548c<code>plt.ylim()<\/code>\u6765\u8bbe\u7f6eX\u8f74\u548cY\u8f74\u7684\u8303\u56f4\u3002\u8fd9\u5bf9\u4e8e\u786e\u4fdd\u6240\u6709\u66f2\u7ebf\u90fd\u80fd\u6e05\u6670\u53ef\u89c1\u975e\u5e38\u91cd\u8981\uff0c\u7279\u522b\u662f\u5728\u66f2\u7ebf\u6570\u76ee\u8f83\u591a\u6216\u6570\u503c\u8303\u56f4\u5dee\u5f02\u8f83\u5927\u7684\u60c5\u51b5\u4e0b\u3002\u901a\u8fc7\u9002\u5f53\u7684\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5c55\u793a\u6570\u636e\u7684\u8d8b\u52bf\u548c\u5173\u7cfb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5c06\u591a\u6761\u66f2\u7ebf\u7ed8\u5236\u5230\u4e00\u8d77\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u901a\u5e38\u4f7f\u7528\u7684\u5e93\u662fMatplotlib\u3002\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528plo [&hellip;]","protected":false},"author":3,"featured_media":1105492,"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\/1105484"}],"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=1105484"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1105484\/revisions"}],"predecessor-version":[{"id":1105494,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1105484\/revisions\/1105494"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1105492"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1105484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1105484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1105484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}