{"id":1118502,"date":"2025-01-08T18:35:59","date_gmt":"2025-01-08T10:35:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1118502.html"},"modified":"2025-01-08T18:36:01","modified_gmt":"2025-01-08T10:36:01","slug":"python%e5%a6%82%e4%bd%95%e5%81%9a%e5%90%91%e4%b8%8b%e7%9a%84%e6%9f%b1%e7%8a%b6%e5%9b%be","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1118502.html","title":{"rendered":"python\u5982\u4f55\u505a\u5411\u4e0b\u7684\u67f1\u72b6\u56fe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25081952\/3585266d-430f-46a0-961d-cde09d71bb79.webp\" alt=\"python\u5982\u4f55\u505a\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5236\u4f5c\u5411\u4e0b\u7684\u67f1\u72b6\u56fe<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u5236\u4f5c\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Matplotlib\u5e93\u3002<strong>\u9996\u5148\uff0c\u5b89\u88c5Matplotlib\u5e93\u3001\u521b\u5efa\u6570\u636e\u3001\u8bbe\u7f6e\u6761\u5f62\u56fe\u53c2\u6570\u3001\u53cd\u8f6cY\u8f74<\/strong>\u3002\u4e0b\u9762\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5176\u4e2d\u4e00\u4e2a\u6b65\u9aa4\uff0c\u5373\u5982\u4f55\u53cd\u8f6cY\u8f74\u3002<\/p>\n<\/p>\n<p><p>\u53cd\u8f6cY\u8f74\u662f\u5236\u4f5c\u5411\u4e0b\u67f1\u72b6\u56fe\u7684\u5173\u952e\u6b65\u9aa4\u3002\u901a\u8fc7\u8bbe\u7f6eMatplotlib\u7684<code>invert_yaxis()<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06Y\u8f74\u65b9\u5411\u53cd\u8f6c\uff0c\u4f7f\u67f1\u72b6\u56fe\u5411\u4e0b\u5c55\u793a\u3002\u8fd9\u6837\uff0c\u53ef\u4ee5\u6e05\u6670\u5730\u5c55\u793a\u6570\u636e\u7684\u51cf\u5c11\u8d8b\u52bf\u6216\u8d1f\u503c\u6570\u636e\u7684\u5c55\u793a\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5\u548c\u5bfc\u5165\u5e93<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u7ed8\u5236\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Matplotlib\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165Matplotlib\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><p>\u4e8c\u3001\u521b\u5efa\u6570\u636e<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u7528\u4e8e\u7ed8\u5236\u67f1\u72b6\u56fe\u7684\u6570\u636e\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u7ec4\u6570\u636e\uff0c\u8868\u793a\u67d0\u4e9b\u503c\u5728\u4e0d\u540c\u7c7b\u522b\u4e2d\u7684\u5206\u5e03\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">categories = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;]<\/p>\n<p>values = [10, 15, 7, 12, 9]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u8bbe\u7f6e\u6761\u5f62\u56fe\u53c2\u6570<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Matplotlib\u7684<code>barh<\/code>\u65b9\u6cd5\u521b\u5efa\u6a2a\u5411\u7684\u6761\u5f62\u56fe\uff0c\u5e76\u8bbe\u7f6e\u4e00\u4e9b\u53c2\u6570\u4ee5\u786e\u4fdd\u56fe\u8868\u7684\u5916\u89c2\u7b26\u5408\u9884\u671f\u3002\u53ef\u4ee5\u81ea\u5b9a\u4e49\u6761\u5f62\u56fe\u7684\u989c\u8272\u3001\u5bbd\u5ea6\u7b49\u53c2\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 6))  # \u8bbe\u7f6e\u56fe\u8868\u7684\u5927\u5c0f<\/p>\n<p>plt.barh(categories, values, color=&#39;skyblue&#39;)  # \u521b\u5efa\u6a2a\u5411\u6761\u5f62\u56fe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u53cd\u8f6cY\u8f74<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u5c06\u6761\u5f62\u56fe\u5411\u4e0b\u5c55\u793a\uff0c\u9700\u8981\u53cd\u8f6cY\u8f74\u3002\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>invert_yaxis<\/code>\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.gca().invert_yaxis()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u6dfb\u52a0\u6807\u7b7e\u548c\u6807\u9898<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u56fe\u8868\u66f4\u5177\u53ef\u8bfb\u6027\uff0c\u53ef\u4ee5\u6dfb\u52a0\u8f74\u6807\u7b7e\u548c\u6807\u9898\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.xlabel(&#39;Values&#39;)<\/p>\n<p>plt.ylabel(&#39;Categories&#39;)<\/p>\n<p>plt.title(&#39;Downward Bar Chart Example&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u5c55\u793a\u56fe\u8868<\/p>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u4f7f\u7528<code>plt.show()<\/code>\u65b9\u6cd5\u6765\u5c55\u793a\u56fe\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b8c\u6574\u7684Python\u4ee3\u7801\u5982\u4e0b\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<h2><strong>\u6570\u636e<\/strong><\/h2>\n<p>categories = [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;]<\/p>\n<p>values = [10, 15, 7, 12, 9]<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u8868<\/strong><\/h2>\n<p>plt.figure(figsize=(10, 6))  # \u8bbe\u7f6e\u56fe\u8868\u7684\u5927\u5c0f<\/p>\n<p>plt.barh(categories, values, color=&#39;skyblue&#39;)  # \u521b\u5efa\u6a2a\u5411\u6761\u5f62\u56fe<\/p>\n<h2><strong>\u53cd\u8f6cY\u8f74<\/strong><\/h2>\n<p>plt.gca().invert_yaxis()<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u7b7e\u548c\u6807\u9898<\/strong><\/h2>\n<p>plt.xlabel(&#39;Values&#39;)<\/p>\n<p>plt.ylabel(&#39;Categories&#39;)<\/p>\n<p>plt.title(&#39;Downward Bar Chart Example&#39;)<\/p>\n<h2><strong>\u5c55\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Seaborn\u5236\u4f5c\u5411\u4e0b\u7684\u67f1\u72b6\u56fe<\/h3>\n<\/p>\n<p><p>Seaborn\u662f\u4e00\u4e2a\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u53ef\u89c6\u5316\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u52a0\u7f8e\u89c2\u548c\u7b80\u6d01\u7684API\u3002\u4f7f\u7528Seaborn\u4e5f\u53ef\u4ee5\u8f7b\u677e\u5730\u5236\u4f5c\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5\u548c\u5bfc\u5165\u5e93<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Seaborn\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install seaborn<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165Seaborn\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 pandas as pd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u521b\u5efa\u6570\u636e<\/p>\n<\/p>\n<p><p>\u521b\u5efa\u7528\u4e8e\u7ed8\u5236\u67f1\u72b6\u56fe\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528Pandas DataFrame\u6765\u7ec4\u7ec7\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = pd.DataFrame({<\/p>\n<p>    &#39;categories&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;],<\/p>\n<p>    &#39;values&#39;: [10, 15, 7, 12, 9]<\/p>\n<p>})<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528Seaborn\u7ed8\u5236\u6761\u5f62\u56fe<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Seaborn\u7684<code>barplot<\/code>\u65b9\u6cd5\u521b\u5efa\u6761\u5f62\u56fe\uff0c\u5e76\u8bbe\u7f6e\u4e00\u4e9b\u53c2\u6570\u4ee5\u786e\u4fdd\u56fe\u8868\u7684\u5916\u89c2\u7b26\u5408\u9884\u671f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 6))  # \u8bbe\u7f6e\u56fe\u8868\u7684\u5927\u5c0f<\/p>\n<p>sns.barplot(x=&#39;values&#39;, y=&#39;categories&#39;, data=data, color=&#39;skyblue&#39;, orient=&#39;h&#39;)  # \u521b\u5efa\u6a2a\u5411\u6761\u5f62\u56fe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u53cd\u8f6cY\u8f74<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u5c06\u6761\u5f62\u56fe\u5411\u4e0b\u5c55\u793a\uff0c\u9700\u8981\u53cd\u8f6cY\u8f74\u3002\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>invert_yaxis<\/code>\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.gca().invert_yaxis()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u6dfb\u52a0\u6807\u7b7e\u548c\u6807\u9898<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u56fe\u8868\u66f4\u5177\u53ef\u8bfb\u6027\uff0c\u53ef\u4ee5\u6dfb\u52a0\u8f74\u6807\u7b7e\u548c\u6807\u9898\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.xlabel(&#39;Values&#39;)<\/p>\n<p>plt.ylabel(&#39;Categories&#39;)<\/p>\n<p>plt.title(&#39;Downward Bar Chart Example with Seaborn&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u5c55\u793a\u56fe\u8868<\/p>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u4f7f\u7528<code>plt.show()<\/code>\u65b9\u6cd5\u6765\u5c55\u793a\u56fe\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b8c\u6574\u7684Python\u4ee3\u7801\u5982\u4e0b\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>\u6570\u636e<\/strong><\/h2>\n<p>data = pd.DataFrame({<\/p>\n<p>    &#39;categories&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;],<\/p>\n<p>    &#39;values&#39;: [10, 15, 7, 12, 9]<\/p>\n<p>})<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u8868<\/strong><\/h2>\n<p>plt.figure(figsize=(10, 6))  # \u8bbe\u7f6e\u56fe\u8868\u7684\u5927\u5c0f<\/p>\n<p>sns.barplot(x=&#39;values&#39;, y=&#39;categories&#39;, data=data, color=&#39;skyblue&#39;, orient=&#39;h&#39;)  # \u521b\u5efa\u6a2a\u5411\u6761\u5f62\u56fe<\/p>\n<h2><strong>\u53cd\u8f6cY\u8f74<\/strong><\/h2>\n<p>plt.gca().invert_yaxis()<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u7b7e\u548c\u6807\u9898<\/strong><\/h2>\n<p>plt.xlabel(&#39;Values&#39;)<\/p>\n<p>plt.ylabel(&#39;Categories&#39;)<\/p>\n<p>plt.title(&#39;Downward Bar Chart Example with Seaborn&#39;)<\/p>\n<h2><strong>\u5c55\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5728Jupyter Notebook\u4e2d\u5c55\u793a\u5411\u4e0b\u7684\u67f1\u72b6\u56fe<\/h3>\n<\/p>\n<p><p>\u5728Jupyter Notebook\u4e2d\u5c55\u793a\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\u4e0e\u5728Python\u811a\u672c\u4e2d\u5c55\u793a\u57fa\u672c\u76f8\u540c\uff0c\u4f46\u6709\u4e00\u4e9b\u7ec6\u5fae\u7684\u5dee\u5f02\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5728Jupyter Notebook\u4e2d\u5c55\u793a\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5bfc\u5165\u5e93\u5e76\u8bbe\u7f6e\u663e\u793a\u9009\u9879<\/p>\n<\/p>\n<p><p>\u5728Jupyter Notebook\u4e2d\uff0c\u9996\u5148\u5bfc\u5165\u5fc5\u8981\u7684\u5e93\uff0c\u5e76\u8bbe\u7f6eMatplotlib\u7684\u663e\u793a\u9009\u9879\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import seaborn as sns<\/p>\n<p>import pandas as pd<\/p>\n<p>%matplotlib inline  # \u4f7f\u56fe\u8868\u5185\u5d4c\u5728Notebook\u4e2d<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u521b\u5efa\u6570\u636e<\/p>\n<\/p>\n<p><p>\u521b\u5efa\u7528\u4e8e\u7ed8\u5236\u67f1\u72b6\u56fe\u7684\u6570\u636e\uff0c\u4f7f\u7528Pandas DataFrame\u6765\u7ec4\u7ec7\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = pd.DataFrame({<\/p>\n<p>    &#39;categories&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;],<\/p>\n<p>    &#39;values&#39;: [10, 15, 7, 12, 9]<\/p>\n<p>})<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528Seaborn\u7ed8\u5236\u6761\u5f62\u56fe<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Seaborn\u7684<code>barplot<\/code>\u65b9\u6cd5\u521b\u5efa\u6761\u5f62\u56fe\uff0c\u5e76\u8bbe\u7f6e\u4e00\u4e9b\u53c2\u6570\u4ee5\u786e\u4fdd\u56fe\u8868\u7684\u5916\u89c2\u7b26\u5408\u9884\u671f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.figure(figsize=(10, 6))  # \u8bbe\u7f6e\u56fe\u8868\u7684\u5927\u5c0f<\/p>\n<p>sns.barplot(x=&#39;values&#39;, y=&#39;categories&#39;, data=data, color=&#39;skyblue&#39;, orient=&#39;h&#39;)  # \u521b\u5efa\u6a2a\u5411\u6761\u5f62\u56fe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u53cd\u8f6cY\u8f74<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u5c06\u6761\u5f62\u56fe\u5411\u4e0b\u5c55\u793a\uff0c\u9700\u8981\u53cd\u8f6cY\u8f74\u3002\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>invert_yaxis<\/code>\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.gca().invert_yaxis()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u6dfb\u52a0\u6807\u7b7e\u548c\u6807\u9898<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u56fe\u8868\u66f4\u5177\u53ef\u8bfb\u6027\uff0c\u53ef\u4ee5\u6dfb\u52a0\u8f74\u6807\u7b7e\u548c\u6807\u9898\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.xlabel(&#39;Values&#39;)<\/p>\n<p>plt.ylabel(&#39;Categories&#39;)<\/p>\n<p>plt.title(&#39;Downward Bar Chart Example in Jupyter Notebook&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u5c55\u793a\u56fe\u8868<\/p>\n<\/p>\n<p><p>\u5728Jupyter Notebook\u4e2d\uff0c\u56fe\u8868\u4f1a\u81ea\u52a8\u663e\u793a\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u663e\u5f0f\u5730\u8c03\u7528<code>plt.show()<\/code>\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b8c\u6574\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import seaborn as sns<\/p>\n<p>import pandas as pd<\/p>\n<p>%matplotlib inline  # \u4f7f\u56fe\u8868\u5185\u5d4c\u5728Notebook\u4e2d<\/p>\n<h2><strong>\u6570\u636e<\/strong><\/h2>\n<p>data = pd.DataFrame({<\/p>\n<p>    &#39;categories&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;],<\/p>\n<p>    &#39;values&#39;: [10, 15, 7, 12, 9]<\/p>\n<p>})<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u8868<\/strong><\/h2>\n<p>plt.figure(figsize=(10, 6))  # \u8bbe\u7f6e\u56fe\u8868\u7684\u5927\u5c0f<\/p>\n<p>sns.barplot(x=&#39;values&#39;, y=&#39;categories&#39;, data=data, color=&#39;skyblue&#39;, orient=&#39;h&#39;)  # \u521b\u5efa\u6a2a\u5411\u6761\u5f62\u56fe<\/p>\n<h2><strong>\u53cd\u8f6cY\u8f74<\/strong><\/h2>\n<p>plt.gca().invert_yaxis()<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u7b7e\u548c\u6807\u9898<\/strong><\/h2>\n<p>plt.xlabel(&#39;Values&#39;)<\/p>\n<p>plt.ylabel(&#39;Categories&#39;)<\/p>\n<p>plt.title(&#39;Downward Bar Chart Example in Jupyter Notebook&#39;)<\/p>\n<h2><strong>\u5c55\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5c06\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5728\u5b8c\u6210\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\u7ed8\u5236\u540e\uff0c\u53ef\u80fd\u9700\u8981\u5c06\u56fe\u8868\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6\uff0c\u4ee5\u4fbf\u5728\u62a5\u544a\u6216\u5176\u4ed6\u6587\u6863\u4e2d\u4f7f\u7528\u3002\u4f7f\u7528Matplotlib\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u56fe\u8868\u4fdd\u5b58\u4e3a\u591a\u79cd\u683c\u5f0f\u7684\u56fe\u50cf\u6587\u4ef6\uff0c\u5982PNG\u3001JPEG\u3001SVG\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u521b\u5efa\u5e76\u7ed8\u5236\u56fe\u8868<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6309\u7167\u524d\u9762\u7684\u6b65\u9aa4\u521b\u5efa\u5e76\u7ed8\u5236\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import seaborn as sns<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u6570\u636e<\/strong><\/h2>\n<p>data = pd.DataFrame({<\/p>\n<p>    &#39;categories&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;],<\/p>\n<p>    &#39;values&#39;: [10, 15, 7, 12, 9]<\/p>\n<p>})<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u8868<\/strong><\/h2>\n<p>plt.figure(figsize=(10, 6))  # \u8bbe\u7f6e\u56fe\u8868\u7684\u5927\u5c0f<\/p>\n<p>sns.barplot(x=&#39;values&#39;, y=&#39;categories&#39;, data=data, color=&#39;skyblue&#39;, orient=&#39;h&#39;)  # \u521b\u5efa\u6a2a\u5411\u6761\u5f62\u56fe<\/p>\n<h2><strong>\u53cd\u8f6cY\u8f74<\/strong><\/h2>\n<p>plt.gca().invert_yaxis()<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u7b7e\u548c\u6807\u9898<\/strong><\/h2>\n<p>plt.xlabel(&#39;Values&#39;)<\/p>\n<p>plt.ylabel(&#39;Categories&#39;)<\/p>\n<p>plt.title(&#39;Downward Bar Chart Example&#39;)<\/p>\n<h2><strong>\u5c55\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u4fdd\u5b58\u56fe\u8868\u4e3a\u56fe\u50cf\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Matplotlib\u7684<code>savefig<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u56fe\u8868\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6\u3002\u53ef\u4ee5\u6307\u5b9a\u6587\u4ef6\u540d\u548c\u6587\u4ef6\u683c\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.savefig(&#39;downward_bar_chart.png&#39;, format=&#39;png&#39;, dpi=300)  # \u4fdd\u5b58\u4e3aPNG\u683c\u5f0f\uff0c\u5206\u8fa8\u7387\u4e3a300 DPI<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u5b8c\u6574\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u5305\u62ec\u56fe\u8868\u7ed8\u5236\u548c\u4fdd\u5b58\u56fe\u50cf\u6587\u4ef6\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import seaborn as sns<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u6570\u636e<\/strong><\/h2>\n<p>data = pd.DataFrame({<\/p>\n<p>    &#39;categories&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;],<\/p>\n<p>    &#39;values&#39;: [10, 15, 7, 12, 9]<\/p>\n<p>})<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u8868<\/strong><\/h2>\n<p>plt.figure(figsize=(10, 6))  # \u8bbe\u7f6e\u56fe\u8868\u7684\u5927\u5c0f<\/p>\n<p>sns.barplot(x=&#39;values&#39;, y=&#39;categories&#39;, data=data, color=&#39;skyblue&#39;, orient=&#39;h&#39;)  # \u521b\u5efa\u6a2a\u5411\u6761\u5f62\u56fe<\/p>\n<h2><strong>\u53cd\u8f6cY\u8f74<\/strong><\/h2>\n<p>plt.gca().invert_yaxis()<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u7b7e\u548c\u6807\u9898<\/strong><\/h2>\n<p>plt.xlabel(&#39;Values&#39;)<\/p>\n<p>plt.ylabel(&#39;Categories&#39;)<\/p>\n<p>plt.title(&#39;Downward Bar Chart Example&#39;)<\/p>\n<h2><strong>\u5c55\u793a\u56fe\u8868<\/strong><\/h2>\n<p>plt.show()<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u8868\u4e3a\u56fe\u50cf\u6587\u4ef6<\/strong><\/h2>\n<p>plt.savefig(&#39;downward_bar_chart.png&#39;, format=&#39;png&#39;, dpi=300)  # \u4fdd\u5b58\u4e3aPNG\u683c\u5f0f\uff0c\u5206\u8fa8\u7387\u4e3a300 DPI<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Python\u548cMatplotlib\u5e93\u8f7b\u677e\u5730\u521b\u5efa\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a\u56fe\u50cf\u6587\u4ef6\u3002\u65e0\u8bba\u662f\u5728\u6570\u636e\u5206\u6790\u3001\u62a5\u544a\u5236\u4f5c\u8fd8\u662f\u6570\u636e\u53ef\u89c6\u5316\u9879\u76ee\u4e2d\uff0c\u8fd9\u4e9b\u6280\u80fd\u90fd\u975e\u5e38\u5b9e\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u7ed8\u5236\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528Matplotlib\u5e93\u53ef\u4ee5\u8f7b\u677e\u7ed8\u5236\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u67f1\u72b6\u56fe\u7684\u8d77\u59cb\u4f4d\u7f6e\u4e3a\u8d1f\u503c\u6765\u5b9e\u73b0\u8fd9\u4e00\u6548\u679c\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\u5bfc\u5165Matplotlib\u5e93\uff0c\u521b\u5efa\u6570\u636e\uff0c\u8bbe\u7f6e\u67f1\u5b50\u7684\u9ad8\u5ea6\u4e3a\u8d1f\u503c\uff0c\u5e76\u7528<code>bar<\/code>\u51fd\u6570\u7ed8\u5236\u56fe\u5f62\u3002<\/p>\n<p><strong>\u5411\u4e0b\u67f1\u72b6\u56fe\u4e0e\u666e\u901a\u67f1\u72b6\u56fe\u6709\u4ec0\u4e48\u4e0d\u540c\u4e4b\u5904\uff1f<\/strong><br \/>\u5411\u4e0b\u67f1\u72b6\u56fe\u7684\u67f1\u5b50\u662f\u4ece\u4e00\u4e2a\u57fa\u51c6\u7ebf\u5411\u4e0b\u5ef6\u4f38\uff0c\u800c\u666e\u901a\u7684\u67f1\u72b6\u56fe\u5219\u662f\u5411\u4e0a\u5ef6\u4f38\u3002\u901a\u8fc7\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\uff0c\u60a8\u53ef\u4ee5\u66f4\u76f4\u89c2\u5730\u663e\u793a\u8d1f\u503c\u6570\u636e\u6216\u8d8b\u52bf\uff0c\u5c24\u5176\u5728\u6bd4\u8f83\u4e0d\u540c\u7c7b\u522b\u7684\u8d1f\u503c\u65f6\u975e\u5e38\u6709\u6548\u3002<\/p>\n<p><strong>\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9bPython\u5e93\u6765\u5b9e\u73b0\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\uff1f<\/strong><br \/>\u9664\u4e86Matplotlib\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528Seaborn\u548cPlotly\u7b49\u5e93\u6765\u7ed8\u5236\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\u3002Seaborn\u5728\u7f8e\u89c2\u6027\u4e0a\u6709\u5f88\u597d\u7684\u8868\u73b0\uff0c\u800cPlotly\u5219\u63d0\u4f9b\u4e86\u4ea4\u4e92\u5f0f\u7684\u56fe\u8868\u5c55\u793a\u3002\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u4f7f\u6570\u636e\u53ef\u89c6\u5316\u66f4\u5177\u5438\u5f15\u529b\u548c\u6613\u8bfb\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u81ea\u5b9a\u4e49\u5411\u4e0b\u67f1\u72b6\u56fe\u7684\u5916\u89c2\u548c\u6837\u5f0f\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u67f1\u5b50\u7684\u989c\u8272\u3001\u5bbd\u5ea6\u548c\u8fb9\u754c\u6837\u5f0f\u6765\u5b9a\u5236\u5411\u4e0b\u67f1\u72b6\u56fe\u7684\u5916\u89c2\u3002Matplotlib\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53c2\u6570\u9009\u9879\uff0c\u5982<code>color<\/code>\u3001<code>width<\/code>\u548c<code>edgecolor<\/code>\uff0c\u901a\u8fc7\u8fd9\u4e9b\u53c2\u6570\u53ef\u4ee5\u4f7f\u60a8\u7684\u56fe\u8868\u66f4\u52a0\u7f8e\u89c2\u4e14\u7b26\u5408\u54c1\u724c\u98ce\u683c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5236\u4f5c\u5411\u4e0b\u7684\u67f1\u72b6\u56fe \u5728Python\u4e2d\u5236\u4f5c\u5411\u4e0b\u7684\u67f1\u72b6\u56fe\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Matplotlib\u5e93\u3002\u9996\u5148\uff0c [&hellip;]","protected":false},"author":3,"featured_media":1118510,"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\/1118502"}],"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=1118502"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1118502\/revisions"}],"predecessor-version":[{"id":1118511,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1118502\/revisions\/1118511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1118510"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1118502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1118502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1118502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}