{"id":991148,"date":"2024-12-27T08:26:12","date_gmt":"2024-12-27T00:26:12","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/991148.html"},"modified":"2024-12-27T08:26:14","modified_gmt":"2024-12-27T00:26:14","slug":"python-%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90%e9%a5%bc%e5%9b%be","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/991148.html","title":{"rendered":"python \u5982\u4f55\u751f\u6210\u997c\u56fe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065543\/c542b67c-ad1e-4920-a022-bdaa6cac775b.webp\" alt=\"python \u5982\u4f55\u751f\u6210\u997c\u56fe\" \/><\/p>\n<p><p> <strong>Python\u751f\u6210\u997c\u56fe\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528Matplotlib\u5e93\u3001\u63d0\u4f9b\u4e30\u5bcc\u7684\u5b9a\u5236\u9009\u9879\u3001\u652f\u6301\u591a\u79cd\u6570\u636e\u683c\u5f0f\u3002<\/strong><\/p>\n<\/p>\n<p><p>Python\u662f\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u7684\u5f3a\u5927\u5de5\u5177\uff0c\u800c\u751f\u6210\u997c\u56fe\u662f\u5176\u5e38\u7528\u529f\u80fd\u4e4b\u4e00\u3002\u901a\u8fc7\u4f7f\u7528Matplotlib\u5e93\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u751f\u6210\u9ad8\u8d28\u91cf\u7684\u997c\u56fe\u3002Matplotlib\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5b9a\u5236\u9009\u9879\uff0c\u4f7f\u60a8\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u989c\u8272\u3001\u6807\u7b7e\u3001\u8d77\u59cb\u89d2\u5ea6\u7b49\u6765\u81ea\u5b9a\u4e49\u997c\u56fe\u7684\u5916\u89c2\u3002\u6b64\u5916\uff0cMatplotlib\u652f\u6301\u591a\u79cd\u6570\u636e\u683c\u5f0f\uff0c\u8fd9\u4f7f\u5f97\u5b83\u80fd\u591f\u4e0e\u591a\u79cd\u6570\u636e\u6e90\u517c\u5bb9\uff0c\u4ece\u800c\u7b80\u5316\u4e86\u6570\u636e\u53ef\u89c6\u5316\u7684\u8fc7\u7a0b\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528Matplotlib\u5e93\u6765\u751f\u6210\u548c\u5b9a\u5236\u997c\u56fe\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001MATPLOTLIB\u5e93\u4ecb\u7ecd<\/p>\n<\/p>\n<p><p>Matplotlib\u662fPython\u4e2d\u6700\u5e7f\u6cdb\u4f7f\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u63d0\u4f9b\u4e86\u521b\u5efa\u591a\u79cd\u7c7b\u578b\u56fe\u8868\u7684\u529f\u80fd\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u8fd8\u662f\u590d\u6742\u7684\u4e09\u7ef4\u56fe\u5f62\uff0cMatplotlib\u90fd\u80fd\u80dc\u4efb\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u548c\u5bfc\u5165Matplotlib<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u4f7f\u7528Matplotlib\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5b83\u5df2\u7ecf\u5b89\u88c5\u5728\u60a8\u7684Python\u73af\u5883\u4e2d\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u6765\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\u60a8\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165Matplotlib\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>Matplotlib\u7684\u57fa\u672c\u7ed3\u6784<\/strong><\/p>\n<\/p>\n<p><p>Matplotlib\u7684\u6838\u5fc3\u7ec4\u4ef6\u662fFigure\u548cAxes\u3002Figure\u662f\u753b\u5e03\uff0cAxes\u662f\u56fe\u8868\u7684\u5b9e\u9645\u7ed8\u5236\u533a\u57df\u3002\u901a\u8fc7\u8fd9\u79cd\u7ed3\u6784\uff0c\u60a8\u53ef\u4ee5\u5728\u4e00\u4e2aFigure\u4e2d\u521b\u5efa\u591a\u4e2aAxes\uff0c\u4ece\u800c\u5728\u4e00\u4e2a\u753b\u5e03\u4e0a\u5c55\u793a\u591a\u4e2a\u56fe\u8868\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u751f\u6210\u7b80\u5355\u7684\u997c\u56fe<\/p>\n<\/p>\n<p><p>\u751f\u6210\u997c\u56fe\u7684\u57fa\u672c\u65b9\u6cd5\u662f\u4f7f\u7528Matplotlib\u7684<code>pie()<\/code>\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u9700\u8981\u4f20\u5165\u6570\u636e\u548c\u6807\u7b7e\uff0c\u4fbf\u53ef\u751f\u6210\u57fa\u672c\u7684\u997c\u56fe\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u51c6\u5907\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u751f\u6210\u997c\u56fe\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u51c6\u5907\u597d\u6570\u636e\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u7ec4\u6570\u636e\u8868\u793a\u4e0d\u540c\u7c7b\u578b\u6c34\u679c\u7684\u9500\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">labels = [&#39;Apples&#39;, &#39;Bananas&#39;, &#39;Cherries&#39;, &#39;Dates&#39;]<\/p>\n<p>sizes = [15, 30, 45, 10]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ed8\u5236\u997c\u56fe<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>pie()<\/code>\u51fd\u6570\u53ef\u4ee5\u7ed8\u5236\u997c\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.pie(sizes, labels=labels)<\/p>\n<p>plt.axis(&#39;equal&#39;)  # \u4fdd\u8bc1\u997c\u56fe\u662f\u5706\u5f62\u7684<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u7ed8\u5236\u4e00\u4e2a\u7b80\u5355\u7684\u997c\u56fe\uff0c\u5e76\u4f7f\u7528<code>axis(&#39;equal&#39;)<\/code>\u786e\u4fdd\u997c\u56fe\u662f\u5706\u5f62\u800c\u4e0d\u662f\u692d\u5706\u5f62\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5b9a\u5236\u997c\u56fe\u5916\u89c2<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u997c\u56fe\u66f4\u5177\u5438\u5f15\u529b\u6216\u66f4\u80fd\u4f20\u8fbe\u4fe1\u606f\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5bf9\u5176\u8fdb\u884c\u5b9a\u5236\u3002Matplotlib\u63d0\u4f9b\u4e86\u591a\u79cd\u9009\u9879\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6dfb\u52a0\u989c\u8272<\/strong><\/p>\n<\/p>\n<p><p>\u60a8\u53ef\u4ee5\u901a\u8fc7<code>colors<\/code>\u53c2\u6570\u6765\u6307\u5b9a\u6bcf\u4e2a\u90e8\u5206\u7684\u989c\u8272\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">colors = [&#39;gold&#39;, &#39;yellowgreen&#39;, &#39;lightcoral&#39;, &#39;lightskyblue&#39;]<\/p>\n<p>plt.pie(sizes, labels=labels, colors=colors)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7a81\u51fa\u663e\u793a\u67d0\u4e00\u90e8\u5206<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u5e0c\u671b\u7a81\u51fa\u663e\u793a\u67d0\u4e2a\u90e8\u5206\uff0c\u53ef\u4ee5\u4f7f\u7528<code>explode<\/code>\u53c2\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">explode = (0, 0.1, 0, 0)  # \u5c06\u7b2c\u4e8c\u4e2a\u90e8\u5206\uff08Bananas\uff09\u5411\u5916\u7a81\u51fa<\/p>\n<p>plt.pie(sizes, explode=explode, labels=labels, colors=colors)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6dfb\u52a0\u767e\u5206\u6bd4\u6807\u7b7e<\/strong><\/p>\n<\/p>\n<p><p><code>autopct<\/code>\u53c2\u6570\u53ef\u4ee5\u7528\u4e8e\u5728\u56fe\u4e2d\u6dfb\u52a0\u767e\u5206\u6bd4\u6807\u7b7e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.pie(sizes, labels=labels, colors=colors, autopct=&#39;%1.1f%%&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u8fdb\u9636\u5b9a\u5236\u4e0e\u4ea4\u4e92<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u57fa\u672c\u7684\u5b9a\u5236\u9009\u9879\uff0cMatplotlib\u8fd8\u652f\u6301\u8fdb\u9636\u7684\u5b9a\u5236\u548c\u4ea4\u4e92\u529f\u80fd\uff0c\u4f7f\u5f97\u997c\u56fe\u66f4\u4e3a\u52a8\u6001\u548c\u7f8e\u89c2\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8c03\u6574\u8d77\u59cb\u89d2\u5ea6<\/strong><\/p>\n<\/p>\n<p><p>\u60a8\u53ef\u4ee5\u901a\u8fc7<code>startangle<\/code>\u53c2\u6570\u8c03\u6574\u997c\u56fe\u7684\u8d77\u59cb\u89d2\u5ea6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.pie(sizes, labels=labels, colors=colors, autopct=&#39;%1.1f%%&#39;, startangle=140)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8c03\u6574\u534a\u5f84\u548c\u9634\u5f71<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7<code>radius<\/code>\u53c2\u6570\u8c03\u6574\u997c\u56fe\u7684\u5927\u5c0f\uff0c\u5e76\u901a\u8fc7<code>shadow<\/code>\u53c2\u6570\u6dfb\u52a0\u9634\u5f71\u6548\u679c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.pie(sizes, labels=labels, colors=colors, autopct=&#39;%1.1f%%&#39;, radius=1.2, shadow=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4ea4\u4e92\u5f0f\u56fe\u8868<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528Matplotlib\u4e0eJupyter Notebook\u7684\u7ed3\u5408\uff0c\u53ef\u4ee5\u521b\u5efa\u4ea4\u4e92\u5f0f\u7684\u56fe\u8868\u3002\u5b89\u88c5\u5e76\u4f7f\u7528<code>%matplotlib notebook<\/code>\u53ef\u4ee5\u4f7f\u56fe\u8868\u5177\u6709\u7f29\u653e\u548c\u65cb\u8f6c\u7b49\u4ea4\u4e92\u529f\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">%matplotlib notebook<\/p>\n<p>plt.pie(sizes, labels=labels, colors=colors, autopct=&#39;%1.1f%%&#39;, startangle=140)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u7ed3\u5408PANDAS\u5e93\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6570\u636e\u901a\u5e38\u5b58\u50a8\u5728Pandas\u6570\u636e\u6846\u4e2d\u3002Matplotlib\u53ef\u4ee5\u4e0ePandas\u65e0\u7f1d\u7ed3\u5408\uff0c\u4f7f\u5f97\u6570\u636e\u7684\u53ef\u89c6\u5316\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528Pandas\u5904\u7406\u6570\u636e<\/strong><\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2aCSV\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u6c34\u679c\u9500\u91cf\u7684\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pandas\u8bfb\u53d6\u6570\u636e\u5e76\u8fdb\u884c\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = pd.read_csv(&#39;fruits.csv&#39;)<\/p>\n<p>sizes = data[&#39;Sales&#39;]<\/p>\n<p>labels = data[&#39;Fruit&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Pandas\u6570\u636e\u751f\u6210\u997c\u56fe<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u5c06Pandas\u6570\u636e\u4f20\u9012\u7ed9<code>pie()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u76f4\u63a5\u751f\u6210\u997c\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.pie(sizes, labels=labels, autopct=&#39;%1.1f%%&#39;)<\/p>\n<p>plt.axis(&#39;equal&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u4f7f\u7528SEABORN\u8fdb\u884c\u9ad8\u7ea7\u53ef\u89c6\u5316<\/p>\n<\/p>\n<p><p>Seaborn\u662f\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u53ef\u89c6\u5316\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u4e3a\u7f8e\u89c2\u548c\u7b80\u6d01\u7684\u56fe\u8868\u6837\u5f0f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u548c\u5bfc\u5165Seaborn<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528pip\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><p>\u7136\u540e\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ed3\u5408Seaborn\u751f\u6210\u997c\u56fe<\/strong><\/p>\n<\/p>\n<p><p>\u5c3d\u7ba1Seaborn\u6ca1\u6709\u76f4\u63a5\u7684<code>pie()<\/code>\u51fd\u6570\uff0c\u4f46\u60a8\u53ef\u4ee5\u4f7f\u7528Seaborn\u7684\u8c03\u8272\u677f\u6765\u589e\u5f3aMatplotlib\u997c\u56fe\u7684\u989c\u8272\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">colors = sns.color_palette(&#39;pastel&#39;)[0:4]<\/p>\n<p>plt.pie(sizes, labels=labels, colors=colors, autopct=&#39;%1.1f%%&#39;)<\/p>\n<p>plt.axis(&#39;equal&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u603b\u7ed3\u4e0e\u5b9e\u8df5\u5efa\u8bae<\/p>\n<\/p>\n<p><p>\u751f\u6210\u997c\u56fe\u662f\u6570\u636e\u53ef\u89c6\u5316\u4e2d\u7684\u5e38\u89c1\u9700\u6c42\uff0cPython\u7684Matplotlib\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u4e14\u7075\u6d3b\u7684\u5de5\u5177\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u901a\u8fc7\u5b66\u4e60\u548c\u638c\u63e1Matplotlib\u7684\u57fa\u672c\u7528\u6cd5\u548c\u5b9a\u5236\u9009\u9879\uff0c\u60a8\u53ef\u4ee5\u4e3a\u4e0d\u540c\u7684\u6570\u636e\u96c6\u521b\u5efa\u6e05\u6670\u4e14\u7f8e\u89c2\u7684\u997c\u56fe\u3002\u6b64\u5916\uff0c\u901a\u8fc7\u7ed3\u5408Pandas\u5904\u7406\u6570\u636e\u4ee5\u53ca\u4f7f\u7528Seaborn\u8fdb\u884c\u9ad8\u7ea7\u53ef\u89c6\u5316\uff0c\u60a8\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347\u6570\u636e\u5206\u6790\u548c\u5c55\u793a\u7684\u6548\u679c\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u8df5\u4e2d\uff0c\u5efa\u8bae\u4ece\u7b80\u5355\u7684\u997c\u56fe\u5f00\u59cb\uff0c\u9010\u6b65\u5c1d\u8bd5\u4e0d\u540c\u7684\u5b9a\u5236\u9009\u9879\u548c\u8fdb\u9636\u529f\u80fd\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u5de5\u5177\u3002\u65e0\u8bba\u662f\u4e2a\u4eba\u9879\u76ee\u8fd8\u662f\u4f01\u4e1a\u7ea7\u6570\u636e\u5206\u6790\uff0cPython\u7684\u53ef\u89c6\u5316\u5de5\u5177\u90fd\u80fd\u4e3a\u60a8\u7684\u5de5\u4f5c\u589e\u8272\u4e0d\u5c11\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u997c\u56fe\uff1f<\/strong><br \/>\u5728Python\u4e2d\u521b\u5efa\u997c\u56fe\u901a\u5e38\u4f7f\u7528Matplotlib\u5e93\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88c5Matplotlib\u5e93\uff0c\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pip install matplotlib<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u63a5\u4e0b\u6765\uff0c\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\uff0c\u53ef\u4ee5\u8f7b\u677e\u751f\u6210\u997c\u56fe\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nlabels = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;]\nsizes = [15, 30, 45, 10]\nplt.pie(sizes, labels=labels, autopct=&#39;%1.1f%%&#39;)\nplt.axis(&#39;equal&#39;)  # \u4f7f\u997c\u56fe\u4e3a\u5706\u5f62\nplt.show()\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u8bbe\u7f6e\u6807\u7b7e\u3001\u6570\u636e\u5927\u5c0f\u548c\u767e\u5206\u6bd4\u683c\u5f0f\u3002<\/p>\n<p><strong>\u997c\u56fe\u7684\u5404\u90e8\u5206\u5982\u4f55\u81ea\u5b9a\u4e49\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7Matplotlib\u5e93\u7684\u53c2\u6570\u6765\u81ea\u5b9a\u4e49\u997c\u56fe\u7684\u5404\u4e2a\u90e8\u5206\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>explode<\/code>\u53c2\u6570\u53ef\u4ee5\u7a81\u51fa\u663e\u793a\u7279\u5b9a\u90e8\u5206\uff0c\u4f7f\u7528<code>colors<\/code>\u53c2\u6570\u53ef\u4ee5\u8bbe\u7f6e\u6bcf\u4e2a\u6247\u5f62\u7684\u989c\u8272\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">explode = (0.1, 0, 0, 0)  # \u7a81\u51fa\u663e\u793a\u7b2c\u4e00\u4e2a\u6247\u5f62\ncolors = [&#39;gold&#39;, &#39;lightcoral&#39;, &#39;lightskyblue&#39;, &#39;lightgreen&#39;]\nplt.pie(sizes, labels=labels, autopct=&#39;%1.1f%%&#39;, explode=explode, colors=colors)\nplt.axis(&#39;equal&#39;)\nplt.show()\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u8ba9\u997c\u56fe\u66f4\u5177\u89c6\u89c9\u5438\u5f15\u529b\u3002<\/p>\n<p><strong>\u997c\u56fe\u5728\u6570\u636e\u53ef\u89c6\u5316\u4e2d\u7684\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u997c\u56fe\u901a\u5e38\u7528\u4e8e\u5c55\u793a\u5404\u90e8\u5206\u5360\u6574\u4f53\u7684\u6bd4\u4f8b\uff0c\u9002\u5408\u7528\u6765\u8868\u793a\u6570\u636e\u4e2d\u4e0d\u540c\u7c7b\u522b\u7684\u76f8\u5bf9\u5927\u5c0f\u3002\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u5305\u62ec\u5e02\u573a\u4efd\u989d\u5206\u6790\u3001\u6295\u7968\u7ed3\u679c\u5206\u5e03\u3001\u9884\u7b97\u5206\u914d\u7b49\u3002\u5728\u9009\u62e9\u4f7f\u7528\u997c\u56fe\u65f6\uff0c\u5e94\u786e\u4fdd\u6570\u636e\u7c7b\u522b\u4e0d\u5b9c\u8fc7\u591a\uff0c\u4ee5\u514d\u56fe\u5f62\u53d8\u5f97\u96be\u4ee5\u89e3\u8bfb\u3002\u5bf9\u4e8e\u7c7b\u522b\u8f83\u591a\u6216\u6570\u503c\u63a5\u8fd1\u7684\u60c5\u51b5\uff0c\u5efa\u8bae\u4f7f\u7528\u5176\u4ed6\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5982\u6761\u5f62\u56fe\u6216\u6298\u7ebf\u56fe\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u751f\u6210\u997c\u56fe\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528Matplotlib\u5e93\u3001\u63d0\u4f9b\u4e30\u5bcc\u7684\u5b9a\u5236\u9009\u9879\u3001\u652f\u6301\u591a\u79cd\u6570\u636e\u683c\u5f0f\u3002 Python [&hellip;]","protected":false},"author":3,"featured_media":991154,"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\/991148"}],"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=991148"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/991148\/revisions"}],"predecessor-version":[{"id":991157,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/991148\/revisions\/991157"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/991154"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=991148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=991148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=991148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}