{"id":1018863,"date":"2024-12-27T12:47:19","date_gmt":"2024-12-27T04:47:19","guid":{"rendered":""},"modified":"2024-12-27T12:47:30","modified_gmt":"2024-12-27T04:47:30","slug":"python%e5%a6%82%e4%bd%95%e7%bb%98%e5%88%b6%e9%9a%8f%e6%9c%ba%e6%95%a3%e7%82%b9%e5%9b%be","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1018863.html","title":{"rendered":"python\u5982\u4f55\u7ed8\u5236\u968f\u673a\u6563\u70b9\u56fe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25161455\/78db982a-dd12-4ee1-ab0a-9f46d6331166.webp\" alt=\"python\u5982\u4f55\u7ed8\u5236\u968f\u673a\u6563\u70b9\u56fe\" \/><\/p>\n<p><p> \u7ed8\u5236\u968f\u673a\u6563\u70b9\u56fe\u5728Python\u4e2d\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u6570\u636e\u53ef\u89c6\u5316\u4efb\u52a1\uff0c\u901a\u5e38\u4f7f\u7528matplotlib\u5e93\u6765\u5b9e\u73b0\u3002<strong>\u901a\u8fc7\u751f\u6210\u968f\u673a\u6570\u3001\u6307\u5b9a\u5750\u6807\u8f74\u3001\u8bbe\u7f6e\u70b9\u7684\u989c\u8272\u548c\u5927\u5c0f\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u89c6\u89c9\u5438\u5f15\u529b\u7684\u968f\u673a\u6563\u70b9\u56fe<\/strong>\u3002\u9996\u5148\uff0c\u5229\u7528NumPy\u5e93\u751f\u6210\u968f\u673a\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528matplotlib\u5e93\u8fdb\u884c\u7ed8\u5236\u548c\u81ea\u5b9a\u4e49\u56fe\u5f62\u3002<strong>\u8fd9\u4e0d\u4ec5\u4ec5\u5c55\u793a\u4e86\u6570\u636e\u7684\u5206\u5e03\uff0c\u8fd8\u53ef\u4ee5\u5e2e\u52a9\u8bc6\u522b\u6a21\u5f0f\u6216\u5f02\u5e38\u503c<\/strong>\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u751f\u6210\u968f\u673a\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u521b\u5efa\u968f\u673a\u6563\u70b9\u56fe\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u751f\u6210\u968f\u673a\u6570\u636e\u3002NumPy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5e93\uff0c\u53ef\u4ee5\u751f\u6210\u968f\u673a\u6570\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>numpy.random<\/code>\u6a21\u5757\u6765\u521b\u5efa\u4e00\u7ec4\u968f\u673a\u6570\u636e\u70b9\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528NumPy\u751f\u6210\u968f\u673a\u6570<\/h4>\n<\/p>\n<p><p>NumPy\u63d0\u4f9b\u4e86\u591a\u79cd\u751f\u6210\u968f\u673a\u6570\u7684\u65b9\u6cd5\u3002\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528<code>numpy.random.rand()<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u751f\u6210\u5728[0, 1)\u533a\u95f4\u4e0a\u7684\u5747\u5300\u5206\u5e03\u968f\u673a\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u751f\u6210100\u4e2a\u968f\u673a\u70b9<\/strong><\/h2>\n<p>x = np.random.rand(100)<\/p>\n<p>y = np.random.rand(100)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u751f\u6210\u7684\u968f\u673a\u6570\u53ef\u4ee5\u7528\u4e8e\u6563\u70b9\u56fe\u7684x\u8f74\u548cy\u8f74\u5750\u6807\u3002<\/p>\n<\/p>\n<p><h4>2. \u751f\u6210\u7279\u5b9a\u5206\u5e03\u7684\u968f\u673a\u6570<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u751f\u6210\u7279\u5b9a\u5206\u5e03\u7684\u968f\u673a\u6570\uff0c\u4f8b\u5982\u6b63\u6001\u5206\u5e03\uff0c\u53ef\u4ee5\u4f7f\u7528<code>numpy.random.normal()<\/code>\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u9700\u8981\u6307\u5b9a\u5747\u503c\u548c\u6807\u51c6\u5dee\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u6b63\u6001\u5206\u5e03\u7684\u968f\u673a\u70b9<\/p>\n<p>x = np.random.normal(0, 1, 100)<\/p>\n<p>y = np.random.normal(0, 1, 100)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8c03\u6574\u5747\u503c\u548c\u6807\u51c6\u5dee\uff0c\u53ef\u4ee5\u63a7\u5236\u6570\u636e\u7684\u96c6\u4e2d\u8d8b\u52bf\u548c\u79bb\u6563\u7a0b\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Matplotlib\u7ed8\u5236\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><p>\u6709\u4e86\u968f\u673a\u6570\u636e\u540e\uff0c\u63a5\u4e0b\u6765\u4f7f\u7528matplotlib\u5e93\u7ed8\u5236\u6563\u70b9\u56fe\u3002<\/p>\n<\/p>\n<p><h4>1. \u57fa\u672c\u6563\u70b9\u56fe\u7ed8\u5236<\/h4>\n<\/p>\n<p><p>Matplotlib\u4e2d\u7684<code>scatter()<\/code>\u51fd\u6570\u7528\u4e8e\u7ed8\u5236\u6563\u70b9\u56fe\u3002\u6700\u7b80\u5355\u7684\u7528\u6cd5\u662f\u5c06x\u548cy\u6570\u636e\u4f20\u9012\u7ed9\u8be5\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.scatter(x, y)<\/p>\n<p>plt.title(&quot;Random Scatter Plot&quot;)<\/p>\n<p>plt.xlabel(&quot;X-axis&quot;)<\/p>\n<p>plt.ylabel(&quot;Y-axis&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u751f\u6210\u4e00\u4e2a\u7b80\u5355\u7684\u968f\u673a\u6563\u70b9\u56fe\u3002<\/p>\n<\/p>\n<p><h4>2. \u8bbe\u7f6e\u70b9\u7684\u989c\u8272\u548c\u5927\u5c0f<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7<code>scatter()<\/code>\u51fd\u6570\u7684\u53c2\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u81ea\u5b9a\u4e49\u70b9\u7684\u989c\u8272\u548c\u5927\u5c0f\u3002<code>c<\/code>\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u989c\u8272\uff0c<code>s<\/code>\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u5927\u5c0f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bbe\u7f6e\u70b9\u7684\u989c\u8272\u548c\u5927\u5c0f<\/p>\n<p>colors = np.random.rand(100)<\/p>\n<p>sizes = 100 * np.random.rand(100)<\/p>\n<p>plt.scatter(x, y, c=colors, s=sizes, alpha=0.5, cmap=&#39;viridis&#39;)<\/p>\n<p>plt.title(&quot;Colored Random Scatter Plot&quot;)<\/p>\n<p>plt.xlabel(&quot;X-axis&quot;)<\/p>\n<p>plt.ylabel(&quot;Y-axis&quot;)<\/p>\n<p>plt.colorbar()  # \u663e\u793a\u989c\u8272\u6761<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6563\u70b9\u56fe\u4e0d\u4ec5\u4ec5\u663e\u793a\u70b9\u7684\u4f4d\u7f6e\uff0c\u8fd8\u80fd\u901a\u8fc7\u989c\u8272\u548c\u5927\u5c0f\u4f20\u8fbe\u66f4\u591a\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u589e\u5f3a\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u6563\u70b9\u56fe\u66f4\u5177\u4fe1\u606f\u6027\u548c\u7f8e\u89c2\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u81ea\u5b9a\u4e49\u548c\u589e\u5f3a\u3002<\/p>\n<\/p>\n<p><h4>1. \u6dfb\u52a0\u7f51\u683c\u548c\u9650\u5236\u5750\u6807\u8f74<\/h4>\n<\/p>\n<p><p>\u7f51\u683c\u7ebf\u6709\u52a9\u4e8e\u66f4\u597d\u5730\u89c2\u5bdf\u6570\u636e\u70b9\u7684\u4f4d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528<code>plt.grid()<\/code>\u51fd\u6570\u6dfb\u52a0\u7f51\u683c\u7ebf\u3002\u5750\u6807\u8f74\u7684\u8303\u56f4\u53ef\u4ee5\u901a\u8fc7<code>plt.xlim()<\/code>\u548c<code>plt.ylim()<\/code>\u6765\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.scatter(x, y, c=colors, s=sizes, alpha=0.5, cmap=&#39;viridis&#39;)<\/p>\n<p>plt.title(&quot;Enhanced Random Scatter Plot&quot;)<\/p>\n<p>plt.xlabel(&quot;X-axis&quot;)<\/p>\n<p>plt.ylabel(&quot;Y-axis&quot;)<\/p>\n<p>plt.xlim(-3, 3)<\/p>\n<p>plt.ylim(-3, 3)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.colorbar()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u66f4\u597d\u5730\u7406\u89e3\u6570\u636e\u7684\u5206\u5e03\u548c\u8303\u56f4\u3002<\/p>\n<\/p>\n<p><h4>2. \u6dfb\u52a0\u6ce8\u91ca\u548c\u6807\u8bb0<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u9700\u8981\u5728\u6563\u70b9\u56fe\u4e0a\u6807\u8bb0\u7279\u5b9a\u7684\u6570\u636e\u70b9\u6216\u6dfb\u52a0\u6ce8\u91ca\u3002\u53ef\u4ee5\u4f7f\u7528<code>plt.annotate()<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.scatter(x, y, c=colors, s=sizes, alpha=0.5, cmap=&#39;viridis&#39;)<\/p>\n<p>plt.title(&quot;Annotated Random 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>\u6807\u8bb0\u7279\u5b9a\u70b9<\/strong><\/h2>\n<p>plt.annotate(&#39;Special Point&#39;, xy=(x[0], y[0]), xytext=(x[0]+0.5, y[0]+0.5),<\/p>\n<p>             arrowprops=dict(facecolor=&#39;black&#39;, shrink=0.05))<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.colorbar()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u6807\u8bb0\u53ef\u4ee5\u5728\u6570\u636e\u5206\u6790\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u5c24\u5176\u662f\u5f53\u4f60\u60f3\u8981\u5f3a\u8c03\u7279\u5b9a\u7684\u89c2\u6d4b\u503c\u65f6\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Pandas\u4e0eSeaborn\u8fdb\u884c\u9ad8\u7ea7\u7ed8\u56fe<\/h3>\n<\/p>\n<p><p>\u9664\u4e86matplotlib\uff0cpandas\u548cseaborn\u4e5f\u662f\u6570\u636e\u53ef\u89c6\u5316\u7684\u5f3a\u5927\u5de5\u5177\u3002\u5b83\u4eec\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u548c\u7b80\u5316\u7684\u7ed8\u56fe\u63a5\u53e3\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Pandas\u7ed8\u5236\u6563\u70b9\u56fe<\/h4>\n<\/p>\n<p><p>Pandas\u7684DataFrame\u5bf9\u8c61\u96c6\u6210\u4e86\u76f4\u63a5\u7ed8\u5236\u56fe\u5f62\u7684\u80fd\u529b\uff0c\u4f7f\u7528<code>plot.scatter()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5feb\u901f\u7ed8\u5236\u6563\u70b9\u56fe\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efaDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame({&#39;x&#39;: x, &#39;y&#39;: y, &#39;colors&#39;: colors, &#39;sizes&#39;: sizes})<\/p>\n<h2><strong>\u4f7f\u7528pandas\u7ed8\u5236\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>df.plot.scatter(x=&#39;x&#39;, y=&#39;y&#39;, c=&#39;colors&#39;, s=&#39;sizes&#39;, colormap=&#39;viridis&#39;, alpha=0.5)<\/p>\n<p>plt.title(&quot;Pandas Scatter Plot&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u5bf9\u4e8e\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u975e\u5e38\u6709\u7528\uff0c\u56e0\u4e3aDataFrame\u5141\u8bb8\u76f4\u63a5\u64cd\u4f5c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528Seaborn\u8fdb\u884c\u589e\u5f3a\u7ed8\u56fe<\/h4>\n<\/p>\n<p><p>Seaborn\u662f\u57fa\u4e8ematplotlib\u7684\u9ad8\u7ea7\u53ef\u89c6\u5316\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u7f8e\u89c2\u7684\u9ed8\u8ba4\u6837\u5f0f\u548c\u66f4\u7b80\u5355\u7684\u63a5\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<h2><strong>\u4f7f\u7528seaborn\u7ed8\u5236\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>sns.scatterplot(x=x, y=y, hue=colors, size=sizes, palette=&#39;viridis&#39;, sizes=(20, 200), alpha=0.5)<\/p>\n<p>plt.title(&quot;Seaborn Scatter Plot&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Seaborn\u7684\u4f18\u52bf\u5728\u4e8e\u5176\u4e30\u5bcc\u7684\u8c03\u8272\u677f\u548c\u5bf9\u590d\u6742\u56fe\u5f62\u7684\u652f\u6301\uff0c\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u51fa\u8272\u7684\u89c6\u89c9\u6548\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5e94\u7528\u573a\u666f\u4e0e\u6848\u4f8b\u5206\u6790<\/h3>\n<\/p>\n<p><p>\u6563\u70b9\u56fe\u5728\u6570\u636e\u5206\u6790\u4e2d\u7684\u5e94\u7528\u975e\u5e38\u5e7f\u6cdb\uff0c\u53ef\u4ee5\u7528\u6765\u63a2\u7d22\u6570\u636e\u7684\u5173\u7cfb\u3001\u6a21\u5f0f\u548c\u5f02\u5e38\u503c\u3002<\/p>\n<\/p>\n<p><h4>1. \u5206\u6790\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u89c2\u5bdf\u6563\u70b9\u56fe\u4e2d\u70b9\u7684\u5206\u5e03\uff0c\u53ef\u4ee5\u8bc6\u522b\u4e24\u4e2a\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u4f8b\u5982\uff0c\u6b63\u76f8\u5173\u3001\u8d1f\u76f8\u5173\u6216\u65e0\u5173\u3002<\/p>\n<\/p>\n<p><h4>2. \u8bc6\u522b\u5f02\u5e38\u503c<\/h4>\n<\/p>\n<p><p>\u6563\u70b9\u56fe\u53ef\u4ee5\u5e2e\u52a9\u8bc6\u522b\u5f02\u5e38\u503c\uff0c\u8fd9\u4e9b\u70b9\u5728\u56fe\u4e2d\u901a\u5e38\u4e0e\u5176\u4ed6\u70b9\u5206\u5e03\u663e\u8457\u4e0d\u540c\u3002<\/p>\n<\/p>\n<p><h4>3. \u7fa4\u4f53\u805a\u7c7b\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u6709\u591a\u4e2a\u53d8\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528\u989c\u8272\u548c\u5927\u5c0f\u6765\u8868\u793a\u4e0d\u540c\u7684\u7fa4\u4f53\uff0c\u4ece\u800c\u5728\u56fe\u4e2d\u663e\u793a\u6570\u636e\u7684\u805a\u7c7b\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u5206\u6790\uff0c\u6563\u70b9\u56fe\u6210\u4e3a\u6570\u636e\u79d1\u5b66\u5bb6\u548c\u5206\u6790\u5e08\u7684\u91cd\u8981\u5de5\u5177\uff0c\u5e2e\u52a9\u4ed6\u4eec\u4ece\u6570\u636e\u4e2d\u53d1\u73b0\u6709\u4ef7\u503c\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u7ed8\u5236\u968f\u673a\u6563\u70b9\u56fe\u662fPython\u6570\u636e\u53ef\u89c6\u5316\u4e2d\u7684\u4e00\u4e2a\u57fa\u672c\u4efb\u52a1\u3002\u901a\u8fc7NumPy\u751f\u6210\u968f\u673a\u6570\u636e\uff0c\u518d\u4f7f\u7528Matplotlib\u7ed8\u5236\u56fe\u5f62\uff0c\u53ef\u4ee5\u521b\u5efa\u51fa\u8272\u7684\u89c6\u89c9\u6548\u679c\u3002\u8fdb\u4e00\u6b65\u7684\u589e\u5f3a\u548c\u81ea\u5b9a\u4e49\uff0c\u4f8b\u5982\u4f7f\u7528Pandas\u548cSeaborn\uff0c\u53ef\u4ee5\u5e2e\u52a9\u521b\u5efa\u66f4\u9ad8\u7ea7\u7684\u56fe\u5f62\u3002\u6563\u70b9\u56fe\u4e0d\u4ec5\u80fd\u5c55\u793a\u6570\u636e\u7684\u5206\u5e03\uff0c\u8fd8\u80fd\u63ed\u793a\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3001\u8bc6\u522b\u5f02\u5e38\u503c\u548c\u5206\u6790\u805a\u7c7b\u60c5\u51b5\uff0c\u662f\u6570\u636e\u5206\u6790\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u751f\u6210\u968f\u673a\u6570\u636e\u7528\u4e8e\u6563\u70b9\u56fe\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u751f\u6210\u968f\u673a\u6570\u636e\u3002\u901a\u8fc7<code>numpy.random.rand()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u751f\u6210\u4e00\u5b9a\u8303\u56f4\u5185\u7684\u968f\u673a\u6570\uff0c\u4f5c\u4e3a\u6563\u70b9\u56fe\u7684x\u548cy\u5750\u6807\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">import numpy as np\nx = np.random.rand(100)  # \u751f\u6210100\u4e2a\u968f\u673ax\u5750\u6807\ny = np.random.rand(100)  # \u751f\u6210100\u4e2a\u968f\u673ay\u5750\u6807\n<\/code><\/pre>\n<p><strong>\u7ed8\u5236\u6563\u70b9\u56fe\u9700\u8981\u4f7f\u7528\u54ea\u4e9b\u5e93\uff1f<\/strong><br \/>\u7ed8\u5236\u6563\u70b9\u56fe\u901a\u5e38\u4f7f\u7528Matplotlib\u5e93\u3002\u5b83\u662fPython\u4e2d\u6700\u6d41\u884c\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u63d0\u4f9b\u4e86\u591a\u79cd\u7ed8\u56fe\u529f\u80fd\uff0c\u80fd\u591f\u8f7b\u677e\u521b\u5efa\u6563\u70b9\u56fe\u3002\u9664\u4e86Matplotlib\uff0cSeaborn\u4e5f\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9\uff0c\u7279\u522b\u9002\u5408\u505a\u7edf\u8ba1\u56fe\u8868\u3002<\/p>\n<p><strong>\u5982\u4f55\u81ea\u5b9a\u4e49\u6563\u70b9\u56fe\u7684\u6837\u5f0f\u548c\u989c\u8272\uff1f<\/strong><br \/>\u5728Matplotlib\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>scatter()<\/code>\u51fd\u6570\u7684\u53c2\u6570\u6765\u8c03\u6574\u6563\u70b9\u7684\u6837\u5f0f\u548c\u989c\u8272\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u8bbe\u7f6e<code>c<\/code>\u53c2\u6570\u6765\u6307\u5b9a\u989c\u8272\uff0c<code>s<\/code>\u53c2\u6570\u6765\u63a7\u5236\u70b9\u7684\u5927\u5c0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\nplt.scatter(x, y, c=&#39;blue&#39;, s=50)  # \u8bbe\u7f6e\u6563\u70b9\u989c\u8272\u4e3a\u84dd\u8272\uff0c\u5927\u5c0f\u4e3a50\nplt.show()\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u5728\u6563\u70b9\u56fe\u4e0a\u6dfb\u52a0\u6807\u9898\u548c\u5750\u6807\u8f74\u6807\u7b7e\uff1f<\/strong><br \/>\u4e3a\u4e86\u4f7f\u6563\u70b9\u56fe\u66f4\u5177\u53ef\u8bfb\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528<code>title()<\/code>\u3001<code>xlabel()<\/code>\u548c<code>ylabel()<\/code>\u51fd\u6570\u6dfb\u52a0\u6807\u9898\u548c\u5750\u6807\u8f74\u6807\u7b7e\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">plt.title(&#39;\u968f\u673a\u6563\u70b9\u56fe\u793a\u4f8b&#39;)\nplt.xlabel(&#39;X\u8f74\u6807\u7b7e&#39;)\nplt.ylabel(&#39;Y\u8f74\u6807\u7b7e&#39;)\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u5e2e\u52a9\u89c2\u4f17\u66f4\u597d\u5730\u7406\u89e3\u56fe\u8868\u7684\u5185\u5bb9\u548c\u542b\u4e49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7ed8\u5236\u968f\u673a\u6563\u70b9\u56fe\u5728Python\u4e2d\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u6570\u636e\u53ef\u89c6\u5316\u4efb\u52a1\uff0c\u901a\u5e38\u4f7f\u7528matplotlib\u5e93\u6765\u5b9e\u73b0\u3002\u901a\u8fc7\u751f\u6210\u968f\u673a\u6570 [&hellip;]","protected":false},"author":3,"featured_media":1018884,"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\/1018863"}],"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=1018863"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1018863\/revisions"}],"predecessor-version":[{"id":1018885,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1018863\/revisions\/1018885"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1018884"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1018863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1018863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1018863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}