{"id":1171802,"date":"2025-01-15T16:40:03","date_gmt":"2025-01-15T08:40:03","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1171802.html"},"modified":"2025-01-15T16:40:07","modified_gmt":"2025-01-15T08:40:07","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8python%e4%b8%ad%e7%94%bb%e6%95%a3%e7%82%b9%e5%9b%be","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1171802.html","title":{"rendered":"\u5982\u4f55\u5728python\u4e2d\u753b\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\/26074041\/a72e759c-a484-4b94-8e5a-f00edf959020.webp\" alt=\"\u5982\u4f55\u5728python\u4e2d\u753b\u6563\u70b9\u56fe\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u753b\u6563\u70b9\u56fe\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5e93\uff0c\u5982Matplotlib\u3001Seaborn\u3001Plotly\u7b49\u3002<\/strong>\u8fd9\u4e9b\u5e93\u5404\u6709\u7279\u8272\uff0cMatplotlib\u662f\u57fa\u7840\u5e93\uff0c\u529f\u80fd\u5f3a\u5927\u4e14\u7075\u6d3b\uff1bSeaborn\u5728Matplotlib\u57fa\u7840\u4e0a\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u7684\u63a5\u53e3\u548c\u9ed8\u8ba4\u6837\u5f0f\uff1bPlotly\u5219\u662f\u4ea4\u4e92\u6027\u548c\u7f8e\u89c2\u6027\u517c\u5907\u7684\u53ef\u89c6\u5316\u5e93\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e09\u4e2a\u5e93\u6765\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u5e76\u4e14\u91cd\u70b9\u8bb2\u89e3Matplotlib\u7684\u4f7f\u7528\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Matplotlib\u7ed8\u5236\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><p>Matplotlib\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u53ef\u89c6\u5316\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ed8\u56fe\u529f\u80fd\u3002\u4e0b\u9762\u662f\u4f7f\u7528Matplotlib\u7ed8\u5236\u6563\u70b9\u56fe\u7684\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h4>1.1\u3001\u5b89\u88c5Matplotlib<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4f7f\u7528\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u786e\u4fddMatplotlib\u5df2\u7ecf\u5b89\u88c5\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Matplotlib\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.2\u3001\u7ed8\u5236\u57fa\u672c\u6563\u70b9\u56fe<\/h4>\n<\/p>\n<p><p>\u7ed8\u5236\u57fa\u672c\u6563\u70b9\u56fe\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u51e0\u884c\u4ee3\u7801\u5373\u53ef\u5b9e\u73b0\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<h2><strong>\u6570\u636e\u51c6\u5907<\/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\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(&#39;Basic Scatter Plot&#39;)<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#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\u9996\u5148\u5bfc\u5165\u4e86Matplotlib\u7684pyplot\u6a21\u5757\uff0c\u7136\u540e\u51c6\u5907\u4e86\u4e24\u4e2a\u5217\u8868<code>x<\/code>\u548c<code>y<\/code>\uff0c\u5206\u522b\u8868\u793a\u6563\u70b9\u56fe\u7684\u6a2a\u8f74\u548c\u7eb5\u8f74\u6570\u636e\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528<code>plt.scatter<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u5e76\u4f7f\u7528<code>plt.title<\/code>\u3001<code>plt.xlabel<\/code>\u548c<code>plt.ylabel<\/code>\u51fd\u6570\u6dfb\u52a0\u6807\u9898\u548c\u8f74\u6807\u7b7e\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>plt.show<\/code>\u51fd\u6570\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h4>1.3\u3001\u8c03\u6574\u6563\u70b9\u56fe\u6837\u5f0f<\/h4>\n<\/p>\n<p><p>Matplotlib\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53c2\u6570\u6765\u8c03\u6574\u6563\u70b9\u56fe\u7684\u6837\u5f0f\u3002\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u6563\u70b9\u7684\u989c\u8272\u3001\u5f62\u72b6\u3001\u5927\u5c0f\u7b49\u5c5e\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u53c2\u6570\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>s<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u5927\u5c0f\u3002<\/li>\n<li><code>c<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u989c\u8272\u3002<\/li>\n<li><code>marker<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u5f62\u72b6\u3002<\/li>\n<li><code>alpha<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u900f\u660e\u5ea6\u3002<\/li>\n<\/ul>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u8c03\u6574\u6563\u70b9\u56fe\u7684\u6837\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u6570\u636e\u51c6\u5907<\/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\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>plt.scatter(x, y, s=100, c=&#39;red&#39;, marker=&#39;x&#39;, alpha=0.5)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898\u548c\u6807\u7b7e<\/strong><\/h2>\n<p>plt.title(&#39;Styled Scatter Plot&#39;)<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#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\u7528<code>s<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u5927\u5c0f\u8bbe\u7f6e\u4e3a100\uff0c\u4f7f\u7528<code>c<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u989c\u8272\u8bbe\u7f6e\u4e3a\u7ea2\u8272\uff0c\u4f7f\u7528<code>marker<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u5f62\u72b6\u8bbe\u7f6e\u4e3a&#39;x&#39;\uff0c\u5e76\u4f7f\u7528<code>alpha<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u900f\u660e\u5ea6\u8bbe\u7f6e\u4e3a0.5\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Seaborn\u7ed8\u5236\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><p>Seaborn\u662f\u4e00\u4e2a\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u53ef\u89c6\u5316\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684\u63a5\u53e3\u548c\u66f4\u7f8e\u89c2\u7684\u9ed8\u8ba4\u6837\u5f0f\u3002\u4f7f\u7528Seaborn\u7ed8\u5236\u6563\u70b9\u56fe\u4e5f\u975e\u5e38\u7b80\u5355\u3002<\/p>\n<\/p>\n<p><h4>2.1\u3001\u5b89\u88c5Seaborn<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4f7f\u7528Seaborn\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u786e\u4fddSeaborn\u5df2\u7ecf\u5b89\u88c5\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Seaborn\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install seaborn<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2\u3001\u7ed8\u5236\u57fa\u672c\u6563\u70b9\u56fe<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Seaborn\u7ed8\u5236\u57fa\u672c\u6563\u70b9\u56fe\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u51e0\u884c\u4ee3\u7801\u5373\u53ef\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\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<h2><strong>\u6570\u636e\u51c6\u5907<\/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\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>sns.scatterplot(x=x, y=y)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898\u548c\u6807\u7b7e<\/strong><\/h2>\n<p>plt.title(&#39;Basic Scatter Plot with Seaborn&#39;)<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#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\u9996\u5148\u5bfc\u5165\u4e86Seaborn\u548cMatplotlib\u7684pyplot\u6a21\u5757\uff0c\u7136\u540e\u51c6\u5907\u4e86\u4e24\u4e2a\u5217\u8868<code>x<\/code>\u548c<code>y<\/code>\uff0c\u5206\u522b\u8868\u793a\u6563\u70b9\u56fe\u7684\u6a2a\u8f74\u548c\u7eb5\u8f74\u6570\u636e\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528<code>sns.scatterplot<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u5e76\u4f7f\u7528<code>plt.title<\/code>\u3001<code>plt.xlabel<\/code>\u548c<code>plt.ylabel<\/code>\u51fd\u6570\u6dfb\u52a0\u6807\u9898\u548c\u8f74\u6807\u7b7e\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>plt.show<\/code>\u51fd\u6570\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h4>2.3\u3001\u8c03\u6574\u6563\u70b9\u56fe\u6837\u5f0f<\/h4>\n<\/p>\n<p><p>Seaborn\u4e5f\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53c2\u6570\u6765\u8c03\u6574\u6563\u70b9\u56fe\u7684\u6837\u5f0f\u3002\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u6563\u70b9\u7684\u989c\u8272\u3001\u5f62\u72b6\u3001\u5927\u5c0f\u7b49\u5c5e\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u53c2\u6570\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>size<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u5927\u5c0f\u3002<\/li>\n<li><code>hue<\/code>\uff1a\u6839\u636e\u67d0\u4e2a\u53d8\u91cf\u8bbe\u7f6e\u6563\u70b9\u7684\u989c\u8272\u3002<\/li>\n<li><code>style<\/code>\uff1a\u6839\u636e\u67d0\u4e2a\u53d8\u91cf\u8bbe\u7f6e\u6563\u70b9\u7684\u5f62\u72b6\u3002<\/li>\n<li><code>alpha<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u900f\u660e\u5ea6\u3002<\/li>\n<\/ul>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u8c03\u6574\u6563\u70b9\u56fe\u7684\u6837\u5f0f\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<h2><strong>\u6570\u636e\u51c6\u5907<\/strong><\/h2>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [2, 3, 5, 7, 11]<\/p>\n<p>sizes = [20, 50, 100, 200, 500]<\/p>\n<p>colors = [&#39;red&#39;, &#39;green&#39;, &#39;blue&#39;, &#39;cyan&#39;, &#39;magenta&#39;]<\/p>\n<h2><strong>\u7ed8\u5236\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>sns.scatterplot(x=x, y=y, size=sizes, hue=colors, palette=&#39;viridis&#39;, alpha=0.7)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898\u548c\u6807\u7b7e<\/strong><\/h2>\n<p>plt.title(&#39;Styled Scatter Plot with Seaborn&#39;)<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#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\u7528<code>size<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u5927\u5c0f\u8bbe\u7f6e\u4e3a\u5217\u8868<code>sizes<\/code>\u4e2d\u7684\u503c\uff0c\u4f7f\u7528<code>hue<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u989c\u8272\u8bbe\u7f6e\u4e3a\u5217\u8868<code>colors<\/code>\u4e2d\u7684\u503c\uff0c\u5e76\u4f7f\u7528<code>alpha<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u900f\u660e\u5ea6\u8bbe\u7f6e\u4e3a0.7\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Plotly\u7ed8\u5236\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><p>Plotly\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u4ea4\u4e92\u5f0f\u53ef\u89c6\u5316\u5e93\uff0c\u5b83\u4e0d\u4ec5\u80fd\u591f\u521b\u5efa\u9759\u6001\u56fe\uff0c\u8fd8\u80fd\u521b\u5efa\u4ea4\u4e92\u5f0f\u56fe\u3002\u4f7f\u7528Plotly\u7ed8\u5236\u6563\u70b9\u56fe\u4e5f\u975e\u5e38\u7b80\u5355\u3002<\/p>\n<\/p>\n<p><h4>3.1\u3001\u5b89\u88c5Plotly<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4f7f\u7528Plotly\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u786e\u4fddPlotly\u5df2\u7ecf\u5b89\u88c5\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Plotly\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install plotly<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2\u3001\u7ed8\u5236\u57fa\u672c\u6563\u70b9\u56fe<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Plotly\u7ed8\u5236\u57fa\u672c\u6563\u70b9\u56fe\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u51e0\u884c\u4ee3\u7801\u5373\u53ef\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.express as px<\/p>\n<h2><strong>\u6570\u636e\u51c6\u5907<\/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\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>fig = px.scatter(x=x, y=y, title=&#39;Basic Scatter Plot with Plotly&#39;, labels={&#39;x&#39;: &#39;X-axis&#39;, &#39;y&#39;: &#39;Y-axis&#39;})<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86Plotly\u7684express\u6a21\u5757\uff0c\u7136\u540e\u51c6\u5907\u4e86\u4e24\u4e2a\u5217\u8868<code>x<\/code>\u548c<code>y<\/code>\uff0c\u5206\u522b\u8868\u793a\u6563\u70b9\u56fe\u7684\u6a2a\u8f74\u548c\u7eb5\u8f74\u6570\u636e\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528<code>px.scatter<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u5e76\u4f7f\u7528<code>title<\/code>\u53c2\u6570\u6dfb\u52a0\u6807\u9898\uff0c\u4f7f\u7528<code>labels<\/code>\u53c2\u6570\u6dfb\u52a0\u8f74\u6807\u7b7e\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>fig.show<\/code>\u51fd\u6570\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h4>3.3\u3001\u8c03\u6574\u6563\u70b9\u56fe\u6837\u5f0f<\/h4>\n<\/p>\n<p><p>Plotly\u4e5f\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53c2\u6570\u6765\u8c03\u6574\u6563\u70b9\u56fe\u7684\u6837\u5f0f\u3002\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u6563\u70b9\u7684\u989c\u8272\u3001\u5f62\u72b6\u3001\u5927\u5c0f\u7b49\u5c5e\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u53c2\u6570\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>size<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u5927\u5c0f\u3002<\/li>\n<li><code>color<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u989c\u8272\u3002<\/li>\n<li><code>symbol<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u5f62\u72b6\u3002<\/li>\n<li><code>opacity<\/code>\uff1a\u8bbe\u7f6e\u6563\u70b9\u7684\u900f\u660e\u5ea6\u3002<\/li>\n<\/ul>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u8c03\u6574\u6563\u70b9\u56fe\u7684\u6837\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.express as px<\/p>\n<h2><strong>\u6570\u636e\u51c6\u5907<\/strong><\/h2>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [2, 3, 5, 7, 11]<\/p>\n<p>sizes = [20, 50, 100, 200, 500]<\/p>\n<p>colors = [&#39;red&#39;, &#39;green&#39;, &#39;blue&#39;, &#39;cyan&#39;, &#39;magenta&#39;]<\/p>\n<h2><strong>\u7ed8\u5236\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>fig = px.scatter(x=x, y=y, size=sizes, color=colors, symbol_sequence=[&#39;circle&#39;, &#39;square&#39;, &#39;diamond&#39;, &#39;cross&#39;, &#39;x&#39;], opacity=0.7, title=&#39;Styled Scatter Plot with Plotly&#39;, labels={&#39;x&#39;: &#39;X-axis&#39;, &#39;y&#39;: &#39;Y-axis&#39;})<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>size<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u5927\u5c0f\u8bbe\u7f6e\u4e3a\u5217\u8868<code>sizes<\/code>\u4e2d\u7684\u503c\uff0c\u4f7f\u7528<code>color<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u989c\u8272\u8bbe\u7f6e\u4e3a\u5217\u8868<code>colors<\/code>\u4e2d\u7684\u503c\uff0c\u4f7f\u7528<code>symbol_sequence<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u5f62\u72b6\u8bbe\u7f6e\u4e3a\u4e0d\u540c\u7684\u7b26\u53f7\uff0c\u5e76\u4f7f\u7528<code>opacity<\/code>\u53c2\u6570\u5c06\u6563\u70b9\u7684\u900f\u660e\u5ea6\u8bbe\u7f6e\u4e3a0.7\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Pandas\u7ed8\u5236\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u6570\u636e\u5206\u6790\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\uff0c\u5e76\u4e14\u53ef\u4ee5\u4e0eMatplotlib\u548cSeaborn\u65e0\u7f1d\u7ed3\u5408\u3002\u4f7f\u7528Pandas\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u5904\u7406\u548c\u7ed8\u5236\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>4.1\u3001\u5b89\u88c5Pandas<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4f7f\u7528Pandas\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u786e\u4fddPandas\u5df2\u7ecf\u5b89\u88c5\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Pandas\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2\u3001\u4f7f\u7528Pandas\u548cMatplotlib\u7ed8\u5236\u6563\u70b9\u56fe<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Pandas\u548cMatplotlib\u7ed3\u5408\u6765\u7ed8\u5236\u6563\u70b9\u56fe\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\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<h2><strong>\u6570\u636e\u51c6\u5907<\/strong><\/h2>\n<p>data = {&#39;x&#39;: [1, 2, 3, 4, 5], &#39;y&#39;: [2, 3, 5, 7, 11]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u7ed8\u5236\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>df.plot.scatter(x=&#39;x&#39;, y=&#39;y&#39;, title=&#39;Scatter Plot with Pandas and Matplotlib&#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\u9996\u5148\u5bfc\u5165\u4e86Pandas\u548cMatplotlib\u7684pyplot\u6a21\u5757\uff0c\u7136\u540e\u51c6\u5907\u4e86\u4e00\u4e2a\u5b57\u5178<code>data<\/code>\uff0c\u5e76\u4f7f\u7528<code>pd.DataFrame<\/code>\u5c06\u5176\u8f6c\u6362\u4e3a\u4e00\u4e2aDataFrame\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528<code>df.plot.scatter<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u5e76\u4f7f\u7528<code>title<\/code>\u53c2\u6570\u6dfb\u52a0\u6807\u9898\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>plt.show<\/code>\u51fd\u6570\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h4>4.3\u3001\u4f7f\u7528Pandas\u548cSeaborn\u7ed8\u5236\u6563\u70b9\u56fe<\/h4>\n<\/p>\n<p><p>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528Pandas\u548cSeaborn\u7ed3\u5408\u6765\u7ed8\u5236\u6563\u70b9\u56fe\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import seaborn as sns<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u6570\u636e\u51c6\u5907<\/strong><\/h2>\n<p>data = {&#39;x&#39;: [1, 2, 3, 4, 5], &#39;y&#39;: [2, 3, 5, 7, 11]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u7ed8\u5236\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>sns.scatterplot(data=df, x=&#39;x&#39;, y=&#39;y&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u9898\u548c\u6807\u7b7e<\/strong><\/h2>\n<p>plt.title(&#39;Scatter Plot with Pandas and Seaborn&#39;)<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#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\u9996\u5148\u5bfc\u5165\u4e86Pandas\u3001Seaborn\u548cMatplotlib\u7684pyplot\u6a21\u5757\uff0c\u7136\u540e\u51c6\u5907\u4e86\u4e00\u4e2a\u5b57\u5178<code>data<\/code>\uff0c\u5e76\u4f7f\u7528<code>pd.DataFrame<\/code>\u5c06\u5176\u8f6c\u6362\u4e3a\u4e00\u4e2aDataFrame\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528<code>sns.scatterplot<\/code>\u51fd\u6570\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u5e76\u4f7f\u7528<code>plt.title<\/code>\u3001<code>plt.xlabel<\/code>\u548c<code>plt.ylabel<\/code>\u51fd\u6570\u6dfb\u52a0\u6807\u9898\u548c\u8f74\u6807\u7b7e\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>plt.show<\/code>\u51fd\u6570\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Matplotlib\u3001Seaborn\u3001Plotly\u548cPandas\u7ed8\u5236\u6563\u70b9\u56fe\u3002<strong>Matplotlib\u662f\u57fa\u7840\u5e93\uff0c\u529f\u80fd\u5f3a\u5927\u4e14\u7075\u6d3b\uff1bSeaborn\u5728Matplotlib\u57fa\u7840\u4e0a\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u7684\u63a5\u53e3\u548c\u9ed8\u8ba4\u6837\u5f0f\uff1bPlotly\u5219\u662f\u4ea4\u4e92\u6027\u548c\u7f8e\u89c2\u6027\u517c\u5907\u7684\u53ef\u89c6\u5316\u5e93\u3002<\/strong>\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u6765\u7ed8\u5236\u6563\u70b9\u56fe\u3002\u65e0\u8bba\u4f60\u9009\u62e9\u54ea\u4e2a\u5e93\uff0c\u5b83\u4eec\u90fd\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53c2\u6570\u6765\u8c03\u6574\u6563\u70b9\u56fe\u7684\u6837\u5f0f\uff0c\u4f7f\u4f60\u53ef\u4ee5\u521b\u5efa\u51fa\u7f8e\u89c2\u4e14\u4fe1\u606f\u4e30\u5bcc\u7684\u56fe\u5f62\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u9009\u62e9\u5408\u9002\u7684\u5e93\u6765\u7ed8\u5236\u6563\u70b9\u56fe\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u6709\u51e0\u4e2a\u6d41\u884c\u7684\u5e93\u53ef\u4ee5\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u5305\u62ecMatplotlib\u3001Seaborn\u548cPlotly\u7b49\u3002Matplotlib\u662f\u6700\u57fa\u7840\u548c\u6700\u5e38\u7528\u7684\u5e93\uff0c\u9002\u5408\u521d\u5b66\u8005\u3002Seaborn\u5728Matplotlib\u7684\u57fa\u7840\u4e0a\u63d0\u4f9b\u4e86\u66f4\u7f8e\u89c2\u7684\u9ed8\u8ba4\u6837\u5f0f\uff0c\u9002\u5408\u8fdb\u884c\u7edf\u8ba1\u56fe\u5f62\u7684\u53ef\u89c6\u5316\u3002Plotly\u5219\u63d0\u4f9b\u4e86\u4ea4\u4e92\u5f0f\u56fe\u5f62\uff0c\u9002\u5408\u9700\u8981\u52a8\u6001\u5c55\u793a\u6570\u636e\u7684\u573a\u666f\u3002\u6839\u636e\u4f60\u7684\u9700\u6c42\u548c\u6570\u636e\u91cf\u9009\u62e9\u5408\u9002\u7684\u5e93\u4f1a\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n<p><strong>\u7ed8\u5236\u6563\u70b9\u56fe\u9700\u8981\u51c6\u5907\u54ea\u4e9b\u6570\u636e\u683c\u5f0f\uff1f<\/strong><br \/>\u4e3a\u4e86\u7ed8\u5236\u6563\u70b9\u56fe\uff0c\u901a\u5e38\u9700\u8981\u4e00\u7ec4X\u8f74\u548cY\u8f74\u7684\u6570\u636e\u70b9\u3002\u8fd9\u4e9b\u6570\u636e\u53ef\u4ee5\u662f\u5217\u8868\u3001NumPy\u6570\u7ec4\u6216Pandas DataFrame\u4e2d\u7684\u5217\u3002\u786e\u4fdd\u6570\u636e\u957f\u5ea6\u76f8\u540c\uff0c\u8fd9\u6837\u6bcf\u4e2aX\u503c\u90fd\u4f1a\u6709\u5bf9\u5e94\u7684Y\u503c\u3002\u6b64\u5916\uff0c\u6570\u636e\u4e2d\u4e0d\u5e94\u5305\u542b\u7f3a\u5931\u503c\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u7ed8\u56fe\u9519\u8bef\u3002\u5bf9\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\uff0c\u786e\u4fdd\u5176\u7b26\u5408\u7ed8\u56fe\u8981\u6c42\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u6563\u70b9\u56fe\u4e2d\u6dfb\u52a0\u4e0d\u540c\u7684\u989c\u8272\u548c\u6807\u8bb0\u6837\u5f0f\uff1f<\/strong><br \/>\u5728Python\u4e2d\u7ed8\u5236\u6563\u70b9\u56fe\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u53c2\u6570\u6765\u6539\u53d8\u70b9\u7684\u989c\u8272\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u5728Matplotlib\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>c<\/code>\u53c2\u6570\u6765\u6307\u5b9a\u989c\u8272\uff0c\u4f7f\u7528<code>s<\/code>\u53c2\u6570\u6765\u8bbe\u7f6e\u70b9\u7684\u5927\u5c0f\u3002Seaborn\u5219\u5141\u8bb8\u901a\u8fc7<code>hue<\/code>\u53c2\u6570\u6839\u636e\u67d0\u4e2a\u5206\u7c7b\u53d8\u91cf\u4e3a\u4e0d\u540c\u7c7b\u522b\u7684\u6570\u636e\u70b9\u8d4b\u4e88\u4e0d\u540c\u7684\u989c\u8272\u3002\u8fd9\u6837\u53ef\u4ee5\u4f7f\u5f97\u56fe\u5f62\u66f4\u6613\u4e8e\u7406\u89e3\u548c\u5206\u6790\uff0c\u5e2e\u52a9\u89c2\u5bdf\u6570\u636e\u4e2d\u7684\u6f5c\u5728\u6a21\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u753b\u6563\u70b9\u56fe\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5e93\uff0c\u5982Matplotlib\u3001Seaborn\u3001Plotly\u7b49\u3002\u8fd9\u4e9b\u5e93\u5404\u6709\u7279\u8272 [&hellip;]","protected":false},"author":3,"featured_media":1171808,"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\/1171802"}],"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=1171802"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1171802\/revisions"}],"predecessor-version":[{"id":1171812,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1171802\/revisions\/1171812"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1171808"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1171802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1171802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1171802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}