{"id":1063099,"date":"2024-12-31T15:57:47","date_gmt":"2024-12-31T07:57:47","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1063099.html"},"modified":"2024-12-31T15:57:49","modified_gmt":"2024-12-31T07:57:49","slug":"python%e5%a6%82%e4%bd%95%e7%bb%98%e5%88%b6%e5%9b%be%e8%a1%a8%e6%b7%bb%e5%8a%a0%e5%9b%be%e4%be%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1063099.html","title":{"rendered":"python\u5982\u4f55\u7ed8\u5236\u56fe\u8868\u6dfb\u52a0\u56fe\u4f8b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/7f7fa17d-669c-40e6-a604-dca12ae96165.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u7ed8\u5236\u56fe\u8868\u6dfb\u52a0\u56fe\u4f8b\" \/><\/p>\n<p><p> <strong>Python\u7ed8\u5236\u56fe\u8868\u548c\u6dfb\u52a0\u56fe\u4f8b\u7684\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Matplotlib\u5e93\u3001\u4f7f\u7528Pandas\u5e93\u3001\u4f7f\u7528Seaborn\u5e93<\/strong>\u3002\u5176\u4e2d\uff0c<strong>Matplotlib<\/strong> \u662f\u6700\u5e38\u7528\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u7ed8\u56fe\u5e93\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u51e0\u79cd\u65b9\u6cd5\uff0c\u5e76\u901a\u8fc7\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u5c55\u793a\u5982\u4f55\u7ed8\u5236\u56fe\u8868\u548c\u6dfb\u52a0\u56fe\u4f8b\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528Matplotlib\u5e93<\/p>\n<\/p>\n<p><p>Matplotlib \u662f Python \u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\uff0c\u63d0\u4f9b\u4e86\u975e\u5e38\u7075\u6d3b\u548c\u4e30\u5bcc\u7684\u7ed8\u56fe\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Matplotlib<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86 Matplotlib \u5e93\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u57fa\u672c\u7ed8\u56fe\u548c\u6dfb\u52a0\u56fe\u4f8b<\/h3>\n<\/p>\n<p><p>Matplotlib \u53ef\u4ee5\u7ed8\u5236\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5982\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u6563\u70b9\u56fe\u7b49\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u7ed8\u5236\u6298\u7ebf\u56fe\u5e76\u6dfb\u52a0\u56fe\u4f8b\u3002<\/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>y1 = [1, 4, 9, 16, 25]<\/p>\n<p>y2 = [1, 2, 3, 4, 5]<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>plt.plot(x, y1, label=&#39;y = x^2&#39;)<\/p>\n<p>plt.plot(x, y2, label=&#39;y = x&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b<\/strong><\/h2>\n<p>plt.legend()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>plt.plot()<\/code> \u65b9\u6cd5\u7ed8\u5236\u4e86\u4e24\u6761\u6298\u7ebf\uff0c\u5e76\u4f7f\u7528 <code>label<\/code> \u53c2\u6570\u4e3a\u6bcf\u6761\u7ebf\u6dfb\u52a0\u4e86\u6807\u7b7e\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528 <code>plt.legend()<\/code> \u65b9\u6cd5\u5728\u56fe\u8868\u4e2d\u6dfb\u52a0\u56fe\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u81ea\u5b9a\u4e49\u56fe\u4f8b<\/h3>\n<\/p>\n<p><p>Matplotlib \u5141\u8bb8\u4f60\u81ea\u5b9a\u4e49\u56fe\u4f8b\u7684\u4f4d\u7f6e\u3001\u5b57\u4f53\u5927\u5c0f\u3001\u989c\u8272\u7b49\u5c5e\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u81ea\u5b9a\u4e49\u9009\u9879\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>y1 = [1, 4, 9, 16, 25]<\/p>\n<p>y2 = [1, 2, 3, 4, 5]<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>plt.plot(x, y1, label=&#39;y = x^2&#39;, color=&#39;blue&#39;, linestyle=&#39;--&#39;)<\/p>\n<p>plt.plot(x, y2, label=&#39;y = x&#39;, color=&#39;red&#39;, linestyle=&#39;-&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b\u5e76\u81ea\u5b9a\u4e49<\/strong><\/h2>\n<p>plt.legend(loc=&#39;upper left&#39;, fontsize=&#39;large&#39;, title=&#39;Functions&#39;, title_fontsize=&#39;medium&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>loc<\/code> \u53c2\u6570\u6307\u5b9a\u56fe\u4f8b\u7684\u4f4d\u7f6e\uff0c\u4f7f\u7528 <code>fontsize<\/code> \u53c2\u6570\u6307\u5b9a\u56fe\u4f8b\u7684\u5b57\u4f53\u5927\u5c0f\uff0c\u4f7f\u7528 <code>title<\/code> \u548c <code>title_fontsize<\/code> \u53c2\u6570\u4e3a\u56fe\u4f8b\u6dfb\u52a0\u6807\u9898\u5e76\u8bbe\u7f6e\u5176\u5b57\u4f53\u5927\u5c0f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528Pandas\u5e93<\/p>\n<\/p>\n<p><p>Pandas \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u5b83\u5185\u7f6e\u4e86\u4e0e Matplotlib \u7684\u96c6\u6210\uff0c\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u7ed8\u5236\u56fe\u8868\u5e76\u6dfb\u52a0\u56fe\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Pandas<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86 Pandas \u5e93\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528Pandas\u7ed8\u5236\u56fe\u8868\u5e76\u6dfb\u52a0\u56fe\u4f8b<\/h3>\n<\/p>\n<p><p>Pandas \u63d0\u4f9b\u4e86 <code>plot<\/code> \u65b9\u6cd5\uff0c\u53ef\u4ee5\u76f4\u63a5\u4ece DataFrame \u6216 Series \u5bf9\u8c61\u4e2d\u751f\u6210\u56fe\u8868\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 Pandas \u7ed8\u5236\u56fe\u8868\u5e76\u6dfb\u52a0\u56fe\u4f8b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;x&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;y1&#39;: [1, 4, 9, 16, 25],<\/p>\n<p>    &#39;y2&#39;: [1, 2, 3, 4, 5]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax = df.plot(x=&#39;x&#39;, y=&#39;y1&#39;, label=&#39;y = x^2&#39;)<\/p>\n<p>df.plot(x=&#39;x&#39;, y=&#39;y2&#39;, label=&#39;y = x&#39;, ax=ax)<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b<\/strong><\/h2>\n<p>plt.legend()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u6570\u636e\u7684 DataFrame\uff0c\u5e76\u4f7f\u7528 <code>plot<\/code> \u65b9\u6cd5\u7ed8\u5236\u4e86\u56fe\u8868\u3002\u6211\u4eec\u8fd8\u4f7f\u7528 <code>ax<\/code> \u53c2\u6570\u5c06\u4e24\u6761\u7ebf\u7ed8\u5236\u5728\u540c\u4e00\u4e2a\u56fe\u8868\u4e0a\uff0c\u5e76\u4f7f\u7528 <code>plt.legend()<\/code> \u65b9\u6cd5\u6dfb\u52a0\u56fe\u4f8b\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528Seaborn\u5e93<\/p>\n<\/p>\n<p><p>Seaborn \u662f\u4e00\u4e2a\u57fa\u4e8e Matplotlib \u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u522b\u7684\u63a5\u53e3\u548c\u9ed8\u8ba4\u6837\u5f0f\uff0c\u4f7f\u7ed8\u56fe\u66f4\u52a0\u7f8e\u89c2\u548c\u7b80\u5355\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Seaborn<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86 Seaborn \u5e93\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install seaborn<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528Seaborn\u7ed8\u5236\u56fe\u8868\u5e76\u6dfb\u52a0\u56fe\u4f8b<\/h3>\n<\/p>\n<p><p>Seaborn \u63d0\u4f9b\u4e86\u591a\u79cd\u7ed8\u56fe\u51fd\u6570\uff0c\u53ef\u4ee5\u7ed8\u5236\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u8868\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 Seaborn \u7ed8\u5236\u56fe\u8868\u5e76\u6dfb\u52a0\u56fe\u4f8b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;x&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;y1&#39;: [1, 4, 9, 16, 25],<\/p>\n<p>    &#39;y2&#39;: [1, 2, 3, 4, 5]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>sns.lineplot(x=&#39;x&#39;, y=&#39;y1&#39;, data=df, label=&#39;y = x^2&#39;)<\/p>\n<p>sns.lineplot(x=&#39;x&#39;, y=&#39;y2&#39;, data=df, label=&#39;y = x&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b<\/strong><\/h2>\n<p>plt.legend()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>sns.lineplot()<\/code> \u65b9\u6cd5\u7ed8\u5236\u4e86\u4e24\u6761\u6298\u7ebf\uff0c\u5e76\u4f7f\u7528 <code>label<\/code> \u53c2\u6570\u4e3a\u6bcf\u6761\u7ebf\u6dfb\u52a0\u4e86\u6807\u7b7e\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528 <code>plt.legend()<\/code> \u65b9\u6cd5\u5728\u56fe\u8868\u4e2d\u6dfb\u52a0\u56fe\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u81ea\u5b9a\u4e49Seaborn\u56fe\u4f8b<\/h3>\n<\/p>\n<p><p>\u4e0e Matplotlib \u7c7b\u4f3c\uff0cSeaborn \u4e5f\u5141\u8bb8\u4f60\u81ea\u5b9a\u4e49\u56fe\u4f8b\u7684\u4f4d\u7f6e\u3001\u5b57\u4f53\u5927\u5c0f\u3001\u989c\u8272\u7b49\u5c5e\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u81ea\u5b9a\u4e49\u9009\u9879\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;x&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;y1&#39;: [1, 4, 9, 16, 25],<\/p>\n<p>    &#39;y2&#39;: [1, 2, 3, 4, 5]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>sns.lineplot(x=&#39;x&#39;, y=&#39;y1&#39;, data=df, label=&#39;y = x^2&#39;, color=&#39;blue&#39;, linestyle=&#39;--&#39;)<\/p>\n<p>sns.lineplot(x=&#39;x&#39;, y=&#39;y2&#39;, data=df, label=&#39;y = x&#39;, color=&#39;red&#39;, linestyle=&#39;-&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u56fe\u4f8b\u5e76\u81ea\u5b9a\u4e49<\/strong><\/h2>\n<p>plt.legend(loc=&#39;upper left&#39;, fontsize=&#39;large&#39;, title=&#39;Functions&#39;, title_fontsize=&#39;medium&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>color<\/code> \u548c <code>linestyle<\/code> \u53c2\u6570\u81ea\u5b9a\u4e49\u4e86\u7ebf\u6761\u7684\u989c\u8272\u548c\u6837\u5f0f\uff0c\u5e76\u4f7f\u7528 <code>plt.legend()<\/code> \u65b9\u6cd5\u81ea\u5b9a\u4e49\u4e86\u56fe\u4f8b\u7684\u4f4d\u7f6e\u3001\u5b57\u4f53\u5927\u5c0f\u548c\u6807\u9898\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528 Matplotlib\u3001Pandas \u548c Seaborn \u5e93\u5728 Python \u4e2d\u7ed8\u5236\u56fe\u8868\u5e76\u6dfb\u52a0\u56fe\u4f8b\u3002<strong>Matplotlib \u63d0\u4f9b\u4e86\u6700\u7075\u6d3b\u548c\u5f3a\u5927\u7684\u7ed8\u56fe\u529f\u80fd\uff0cPandas \u63d0\u4f9b\u4e86\u4e0e\u6570\u636e\u5206\u6790\u7d27\u5bc6\u96c6\u6210\u7684\u7ed8\u56fe\u63a5\u53e3\uff0cSeaborn \u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u522b\u7684\u63a5\u53e3\u548c\u7f8e\u89c2\u7684\u9ed8\u8ba4\u6837\u5f0f<\/strong>\u3002\u6839\u636e\u4f60\u7684\u9700\u6c42\u548c\u504f\u597d\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u9002\u5408\u4f60\u7684\u5e93\u6765\u7ed8\u5236\u56fe\u8868\u548c\u6dfb\u52a0\u56fe\u4f8b\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u4f60\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u7b80\u5355\u7684\u4ee3\u7801\u5b9e\u73b0\u7ed8\u56fe\u548c\u6dfb\u52a0\u56fe\u4f8b\u7684\u529f\u80fd\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u795d\u4f60\u5728\u6570\u636e\u53ef\u89c6\u5316\u7684\u9053\u8def\u4e0a\u53d6\u5f97\u6210\u529f\uff01<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528Matplotlib\u7ed8\u5236\u56fe\u8868\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528Matplotlib\u5e93\u53ef\u4ee5\u8f7b\u677e\u7ed8\u5236\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5305\u62ec\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u6563\u70b9\u56fe\u7b49\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5Matplotlib\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c<code>pip install matplotlib<\/code>\u6765\u5b89\u88c5\u3002\u4f7f\u7528<code>plt.plot()<\/code>\u51fd\u6570\u7ed8\u5236\u56fe\u5f62\uff0c\u5e76\u901a\u8fc7<code>plt.show()<\/code>\u6765\u663e\u793a\u56fe\u8868\u3002\u4f8b\u5982\uff0c\u7ed8\u5236\u7b80\u5355\u6298\u7ebf\u56fe\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nx = [1, 2, 3, 4]\ny = [10, 20, 25, 30]\nplt.plot(x, y)\nplt.show()\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u5728\u56fe\u8868\u4e2d\u6dfb\u52a0\u56fe\u4f8b\uff1f<\/strong><br \/>\u5728Matplotlib\u4e2d\uff0c\u6dfb\u52a0\u56fe\u4f8b\u975e\u5e38\u7b80\u5355\u3002\u53ef\u4ee5\u5728\u7ed8\u5236\u56fe\u5f62\u65f6\uff0c\u4f7f\u7528<code>label<\/code>\u53c2\u6570\u4e3a\u6bcf\u6761\u66f2\u7ebf\u6307\u5b9a\u6807\u7b7e\uff0c\u968f\u540e\u8c03\u7528<code>plt.legend()<\/code>\u51fd\u6570\u6765\u663e\u793a\u56fe\u4f8b\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nx = [1, 2, 3, 4]\ny1 = [10, 20, 25, 30]\ny2 = [15, 25, 20, 35]\n\nplt.plot(x, y1, label=&#39;\u6570\u636e\u96c61&#39;)\nplt.plot(x, y2, label=&#39;\u6570\u636e\u96c62&#39;)\nplt.legend()\nplt.show()\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u81ea\u5b9a\u4e49\u56fe\u4f8b\u7684\u6837\u5f0f\u548c\u4f4d\u7f6e\uff1f<\/strong><br \/>Matplotlib\u5141\u8bb8\u7528\u6237\u81ea\u5b9a\u4e49\u56fe\u4f8b\u7684\u6837\u5f0f\u548c\u4f4d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528<code>loc<\/code>\u53c2\u6570\u6765\u6307\u5b9a\u56fe\u4f8b\u7684\u4f4d\u7f6e\uff0c\u5982<code>loc=&#39;upper left&#39;<\/code>\u3001<code>loc=&#39;lower right&#39;<\/code>\u7b49\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u901a\u8fc7<code>frameon<\/code>\u53c2\u6570\u63a7\u5236\u56fe\u4f8b\u8fb9\u6846\u7684\u663e\u793a\uff0c<code>fontsize<\/code>\u53c2\u6570\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nx = [1, 2, 3, 4]\ny1 = [10, 20, 25, 30]\ny2 = [15, 25, 20, 35]\n\nplt.plot(x, y1, label=&#39;\u6570\u636e\u96c61&#39;)\nplt.plot(x, y2, label=&#39;\u6570\u636e\u96c62&#39;)\nplt.legend(loc=&#39;upper left&#39;, frameon=False, fontsize=&#39;large&#39;)\nplt.show()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Python\u7ed8\u5236\u56fe\u8868\u548c\u6dfb\u52a0\u56fe\u4f8b\u7684\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Matplotlib\u5e93\u3001\u4f7f\u7528Pandas\u5e93\u3001\u4f7f\u7528Seabor [&hellip;]","protected":false},"author":3,"featured_media":1063102,"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\/1063099"}],"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=1063099"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1063099\/revisions"}],"predecessor-version":[{"id":1063107,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1063099\/revisions\/1063107"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1063102"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1063099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1063099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1063099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}