{"id":1077842,"date":"2025-01-08T12:06:02","date_gmt":"2025-01-08T04:06:02","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1077842.html"},"modified":"2025-01-08T12:06:04","modified_gmt":"2025-01-08T04:06:04","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%b0%86%e6%95%a3%e7%82%b9%e8%bf%9e%e7%ba%bf-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1077842.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u5c06\u6563\u70b9\u8fde\u7ebf"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181711\/3935cc50-11c8-4361-b015-e51a633b60fb.webp\" alt=\"python\u4e2d\u5982\u4f55\u5c06\u6563\u70b9\u8fde\u7ebf\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u5c06\u6563\u70b9\u8fde\u7ebf\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528Matplotlib\u3001Seaborn\u3001Plotly\u7b49\u5e93\u6765\u5b9e\u73b0\u3002Matplotlib\u662f\u6700\u5e38\u7528\u7684\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ed8\u56fe\u529f\u80fd\uff0c\u9002\u5408\u5404\u79cd\u7c7b\u578b\u7684\u6570\u636e\u53ef\u89c6\u5316\u9700\u6c42\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Matplotlib\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf\u662f\u6700\u5e38\u89c1\u7684\u505a\u6cd5\u4e4b\u4e00\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5\u5e76\u5bfc\u5165Matplotlib\u5e93\uff0c\u7136\u540e\u751f\u6210\u6570\u636e\u5e76\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u6700\u540e\u901a\u8fc7\u6dfb\u52a0\u7ebf\u6761\u5b9e\u73b0\u8fde\u7ebf\u6548\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Matplotlib\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf<\/h3>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u5f3a\u5927\u7684Python\u7ed8\u56fe\u5e93\uff0c\u9002\u7528\u4e8e2D\u56fe\u5f62\u7684\u7ed8\u5236\u3002\u4ee5\u4e0b\u6b65\u9aa4\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Matplotlib\u5c06\u6563\u70b9\u8fde\u7ebf\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u4e0e\u5bfc\u5165Matplotlib\u5e93<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Matplotlib\u5e93\u3002\u5982\u679c\u5c1a\u672a\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>\u63a5\u4e0b\u6765\uff0c\u5728\u4f60\u7684Python\u811a\u672c\u6216Jupyter Notebook\u4e2d\u5bfc\u5165\u8be5\u5e93\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<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u751f\u6210\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u6211\u4eec\u9700\u8981\u4e00\u4e9b\u6570\u636e\u3002\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528NumPy\u6765\u751f\u6210\u4e00\u4e9b\u968f\u673a\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u968f\u673a\u6570\u636e<\/p>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u6216\u8005\u4f7f\u7528\u5b9e\u9645\u6570\u636e<\/strong><\/h2>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [2, 3, 5, 7, 11]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Matplotlib\u7684<code>scatter<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u4f7f\u7528<code>plot<\/code>\u51fd\u6570\u7ed8\u5236\u8fde\u7ebf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.scatter(x, y, label=&#39;Scatter Points&#39;)<\/p>\n<p>plt.plot(x, y, label=&#39;Line Connection&#39;, color=&#39;r&#39;)<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#39;)<\/p>\n<p>plt.title(&#39;Scatter Plot with Line Connection&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Seaborn\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf<\/h3>\n<\/p>\n<p><p>Seaborn\u662f\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u63a5\u53e3\uff0c\u63d0\u4f9b\u4e86\u66f4\u7f8e\u89c2\u7684\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Seaborn\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u4e0e\u5bfc\u5165Seaborn\u5e93<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u5c1a\u672a\u5b89\u88c5Seaborn\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 seaborn<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u5728\u4f60\u7684Python\u811a\u672c\u6216Jupyter Notebook\u4e2d\u5bfc\u5165\u8be5\u5e93\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 numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u751f\u6210\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u4e0e\u4e4b\u524d\u76f8\u540c\uff0c\u6211\u4eec\u4f7f\u7528NumPy\u751f\u6210\u4e00\u4e9b\u968f\u673a\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u968f\u673a\u6570\u636e<\/p>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u6216\u8005\u4f7f\u7528\u5b9e\u9645\u6570\u636e<\/strong><\/h2>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [2, 3, 5, 7, 11]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Seaborn\u7684<code>scatterplot<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u4f7f\u7528<code>lineplot<\/code>\u51fd\u6570\u7ed8\u5236\u8fde\u7ebf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sns.scatterplot(x=x, y=y, label=&#39;Scatter Points&#39;)<\/p>\n<p>sns.lineplot(x=x, y=y, label=&#39;Line Connection&#39;, color=&#39;r&#39;)<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#39;)<\/p>\n<p>plt.title(&#39;Scatter Plot with Line Connection using Seaborn&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Plotly\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf<\/h3>\n<\/p>\n<p><p>Plotly\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7ed8\u56fe\u5e93\uff0c\u9002\u7528\u4e8e\u521b\u5efa\u9ad8\u5ea6\u4e92\u52a8\u7684\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Plotly\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u4e0e\u5bfc\u5165Plotly\u5e93<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u5c1a\u672a\u5b89\u88c5Plotly\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 plotly<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u5728\u4f60\u7684Python\u811a\u672c\u6216Jupyter Notebook\u4e2d\u5bfc\u5165\u8be5\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.graph_objects as go<\/p>\n<p>import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u751f\u6210\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u4e0e\u4e4b\u524d\u76f8\u540c\uff0c\u6211\u4eec\u4f7f\u7528NumPy\u751f\u6210\u4e00\u4e9b\u968f\u673a\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u968f\u673a\u6570\u636e<\/p>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u6216\u8005\u4f7f\u7528\u5b9e\u9645\u6570\u636e<\/strong><\/h2>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [2, 3, 5, 7, 11]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Plotly\u7684<code>Scatter<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fig = go.Figure()<\/p>\n<h2><strong>\u6dfb\u52a0\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>fig.add_trace(go.Scatter(x=x, y=y, mode=&#39;markers&#39;, name=&#39;Scatter Points&#39;))<\/p>\n<h2><strong>\u6dfb\u52a0\u8fde\u7ebf<\/strong><\/h2>\n<p>fig.add_trace(go.Scatter(x=x, y=y, mode=&#39;lines&#39;, name=&#39;Line Connection&#39;, line=dict(color=&#39;red&#39;)))<\/p>\n<p>fig.update_layout(title=&#39;Scatter Plot with Line Connection using Plotly&#39;,<\/p>\n<p>                  xaxis_title=&#39;X-axis&#39;,<\/p>\n<p>                  yaxis_title=&#39;Y-axis&#39;)<\/p>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Pandas\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf<\/h3>\n<\/p>\n<p><p>Pandas\u5e93\u4e5f\u53ef\u4ee5\u7528\u4e8e\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf\uff0c\u7279\u522b\u662f\u5f53\u6570\u636e\u5b58\u50a8\u5728DataFrame\u4e2d\u65f6\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u4e0e\u5bfc\u5165Pandas\u5e93<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u5c1a\u672a\u5b89\u88c5Pandas\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 pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u5728\u4f60\u7684Python\u811a\u672c\u6216Jupyter Notebook\u4e2d\u5bfc\u5165\u8be5\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u751f\u6210\u6570\u636e\u5e76\u521b\u5efaDataFrame<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pandas\u521b\u5efa\u4e00\u4e2aDataFrame\u6765\u5b58\u50a8\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u6570\u636e<\/p>\n<p>data = {<\/p>\n<p>    &#39;x&#39;: [1, 2, 3, 4, 5],<\/p>\n<p>    &#39;y&#39;: [2, 3, 5, 7, 11]<\/p>\n<p>}<\/p>\n<h2><strong>\u521b\u5efaDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Pandas\u7684<code>plot<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\u56fe\u5e76\u8fde\u7ebf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">ax = df.plot.scatter(x=&#39;x&#39;, y=&#39;y&#39;, label=&#39;Scatter Points&#39;)<\/p>\n<p>df.plot.line(x=&#39;x&#39;, y=&#39;y&#39;, ax=ax, label=&#39;Line Connection&#39;, color=&#39;r&#39;)<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#39;)<\/p>\n<p>plt.title(&#39;Scatter Plot with Line Connection using Pandas&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5c06\u6563\u70b9\u8fde\u7ebf\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u6700\u5e38\u7528\u7684\u662fMatplotlib\u3002\u6b64\u5916\uff0cSeaborn\u3001Plotly\u548cPandas\u4e5f\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ed8\u56fe\u529f\u80fd\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u3002<\/p>\n<\/p>\n<p><p><strong>Matplotlib<\/strong>\uff1a\u9002\u7528\u4e8e\u5927\u591a\u65702D\u7ed8\u56fe\u9700\u6c42\uff0c\u529f\u80fd\u5168\u9762\u3002<\/p>\n<\/p>\n<p><p><strong>Seaborn<\/strong>\uff1a\u57fa\u4e8eMatplotlib\uff0c\u63d0\u4f9b\u66f4\u7f8e\u89c2\u7684\u56fe\u5f62\uff0c\u9002\u5408\u7edf\u8ba1\u6570\u636e\u7684\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<p><p><strong>Plotly<\/strong>\uff1a\u9002\u7528\u4e8e\u4ea4\u4e92\u5f0f\u56fe\u5f62\uff0c\u80fd\u591f\u521b\u5efa\u9ad8\u5ea6\u4e92\u52a8\u7684\u56fe\u8868\u3002<\/p>\n<\/p>\n<p><p><strong>Pandas<\/strong>\uff1a\u9002\u7528\u4e8e\u6570\u636e\u5b58\u50a8\u5728DataFrame\u4e2d\u7684\u60c5\u51b5\uff0c\u65b9\u4fbf\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u7ed8\u56fe\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u5e93\uff0c\u90fd\u53ef\u4ee5\u5b9e\u73b0\u5c06\u6563\u70b9\u8fde\u7ebf\u7684\u6548\u679c\u3002\u901a\u8fc7\u5bf9\u8fd9\u4e9b\u5e93\u7684\u5b66\u4e60\u548c\u5b9e\u8df5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u6ee1\u8db3\u6570\u636e\u53ef\u89c6\u5316\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528matplotlib\u7ed8\u5236\u8fde\u7ebf\u7684\u6563\u70b9\u56fe\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528matplotlib\u5e93\u53ef\u4ee5\u8f7b\u677e\u7ed8\u5236\u8fde\u7ebf\u7684\u6563\u70b9\u56fe\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86matplotlib\u5e93\u3002\u63a5\u7740\uff0c\u53ef\u4ee5\u4f7f\u7528<code>plt.scatter()<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\uff0c\u7136\u540e\u4f7f\u7528<code>plt.plot()<\/code>\u51fd\u6570\u5c06\u8fd9\u4e9b\u70b9\u8fde\u63a5\u8d77\u6765\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\n# \u793a\u4f8b\u6570\u636e\nx = [1, 2, 3, 4, 5]\ny = [2, 3, 5, 7, 11]\n\n# \u7ed8\u5236\u6563\u70b9\nplt.scatter(x, y)\n\n# \u8fde\u63a5\u6563\u70b9\nplt.plot(x, y)\n\nplt.title(&quot;Scatter Plot with Lines&quot;)\nplt.xlabel(&quot;X-axis&quot;)\nplt.ylabel(&quot;Y-axis&quot;)\nplt.show()\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u5305\u542b\u8fde\u7ebf\u7684\u6563\u70b9\u56fe\u3002<\/p>\n<p><strong>\u5728\u7ed8\u5236\u6563\u70b9\u56fe\u65f6\uff0c\u5982\u4f55\u81ea\u5b9a\u4e49\u7ebf\u6761\u7684\u6837\u5f0f\u548c\u989c\u8272\uff1f<\/strong><br \/>\u5728\u4f7f\u7528<code>plt.plot()<\/code>\u51fd\u6570\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u81ea\u5b9a\u4e49\u7ebf\u6761\u7684\u6837\u5f0f\u548c\u989c\u8272\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>color<\/code>\u53c2\u6570\u8bbe\u7f6e\u989c\u8272\uff0c\u4f7f\u7528<code>linestyle<\/code>\u53c2\u6570\u8bbe\u7f6e\u7ebf\u6761\u6837\u5f0f\uff08\u5982\u865a\u7ebf\u3001\u70b9\u7ebf\u7b49\uff09\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">plt.plot(x, y, color=&#39;red&#39;, linestyle=&#39;--&#39;, linewidth=2)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u7ed8\u5236\u4e00\u6761\u7ea2\u8272\u7684\u865a\u7ebf\uff0c\u5bbd\u5ea6\u4e3a2\u4e2a\u50cf\u7d20\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u6563\u70b9\u56fe\u4e2d\u6dfb\u52a0\u6807\u7b7e\u548c\u56fe\u4f8b\uff1f<\/strong><br \/>\u6dfb\u52a0\u6807\u7b7e\u548c\u56fe\u4f8b\u53ef\u4ee5\u5e2e\u52a9\u66f4\u597d\u5730\u7406\u89e3\u56fe\u8868\u3002\u5728\u7ed8\u5236\u6563\u70b9\u548c\u8fde\u7ebf\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>label<\/code>\u53c2\u6570\u4e3a\u6bcf\u4e2a\u7cfb\u5217\u6dfb\u52a0\u6807\u7b7e\u3002\u4f7f\u7528<code>plt.legend()<\/code>\u51fd\u6570\u53ef\u4ee5\u663e\u793a\u56fe\u4f8b\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">plt.scatter(x, y, label=&#39;Data Points&#39;)\nplt.plot(x, y, label=&#39;Connecting Line&#39;, color=&#39;red&#39;)\nplt.legend()\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u4e3a\u6563\u70b9\u548c\u8fde\u7ebf\u6dfb\u52a0\u6807\u7b7e\uff0c\u5e76\u5728\u56fe\u8868\u4e2d\u663e\u793a\u56fe\u4f8b\uff0c\u65b9\u4fbf\u7528\u6237\u8fa8\u8bc6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u5c06\u6563\u70b9\u8fde\u7ebf\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528Matplotlib\u3001Seaborn\u3001Plotly\u7b49\u5e93\u6765 [&hellip;]","protected":false},"author":3,"featured_media":1077850,"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\/1077842"}],"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=1077842"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1077842\/revisions"}],"predecessor-version":[{"id":1077852,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1077842\/revisions\/1077852"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1077850"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1077842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1077842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1077842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}