{"id":933363,"date":"2024-12-26T18:14:24","date_gmt":"2024-12-26T10:14:24","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/933363.html"},"modified":"2024-12-26T18:14:27","modified_gmt":"2024-12-26T10:14:27","slug":"python-ylabel%e5%a6%82%e4%bd%95%e6%89%93%e6%a8%aa","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/933363.html","title":{"rendered":"python ylabel\u5982\u4f55\u6253\u6a2a"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25070826\/a500d8ca-77b0-43a5-a5a5-c2f0fa90b752.webp\" alt=\"python ylabel\u5982\u4f55\u6253\u6a2a\" \/><\/p>\n<p><p> <strong>\u5728Matplotlib\u4e2d\uff0c\u5c06ylabel\u6253\u6a2a\u53ef\u4ee5\u4f7f\u7528<code>labelpad<\/code>\u53c2\u6570\u8c03\u6574\u6807\u7b7e\u4e0e\u8f74\u7684\u8ddd\u79bb\u3001\u4f7f\u7528<code>rotation<\/code>\u53c2\u6570\u8c03\u6574\u6807\u7b7e\u7684\u65cb\u8f6c\u89d2\u5ea6\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7\u8bbe\u7f6e<code>rotation=0<\/code>\u53ef\u4ee5\u5c06ylabel\u6c34\u5e73\u653e\u7f6e\u3002<\/strong>\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Python\u7684Matplotlib\u5e93\u4e2d\u5b9e\u73b0\u8fd9\u4e00\u64cd\u4f5c\uff0c\u4ee5\u53ca\u4e00\u4e9b\u76f8\u5173\u7684\u6280\u5de7\u548c\u793a\u4f8b\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u4e00\u3001MATPLOTLIB\u7b80\u4ecb<\/strong><\/h2>\n<p><p>Matplotlib\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u53ef\u89c6\u5316\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ed8\u56fe\u529f\u80fd\uff0c\u53ef\u4ee5\u751f\u6210\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u8868\u3002\u5728\u6570\u636e\u5206\u6790\u548c\u79d1\u5b66\u8ba1\u7b97\u4e2d\uff0cMatplotlib\u7ecf\u5e38\u7528\u4e8e\u5c55\u793a\u6570\u636e\u7684\u5206\u5e03\u3001\u8d8b\u52bf\u548c\u5173\u7cfb\u3002\u8be5\u5e93\u7684\u7075\u6d3b\u6027\u548c\u5f3a\u5927\u7684\u81ea\u5b9a\u4e49\u529f\u80fd\u4f7f\u5176\u6210\u4e3a\u6570\u636e\u79d1\u5b66\u5bb6\u548c\u7814\u7a76\u4eba\u5458\u7684\u9996\u9009\u5de5\u5177\u4e4b\u4e00\u3002<\/p>\n<\/p>\n<p><p>Matplotlib\u7684\u57fa\u672c\u7ed8\u56fe\u7ed3\u6784\u5305\u62ecFigure\u3001Axes\u3001Axis\u7b49\u5143\u7d20\uff0c\u5176\u4e2dAxes\u662f\u7ed8\u56fe\u7684\u6838\u5fc3\u90e8\u5206\uff0c\u8d1f\u8d23\u7ed8\u5236\u5b9e\u9645\u7684\u56fe\u8868\u548c\u8bbe\u7f6e\u6807\u7b7e\u3001\u523b\u5ea6\u7b49\u5c5e\u6027\u3002\u901a\u8fc7\u4fee\u6539Axes\u7684\u5c5e\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u56fe\u8868\u7684\u9ad8\u5ea6\u81ea\u5b9a\u4e49\uff0c\u5305\u62ec\u8c03\u6574\u6807\u7b7e\u7684\u65cb\u8f6c\u89d2\u5ea6\u548c\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<h2><strong>\u4e8c\u3001YLABEL\u7684\u57fa\u672c\u8bbe\u7f6e<\/strong><\/h2>\n<p><h2>1\u3001\u8bbe\u7f6eYLABEL<\/h2>\n<\/p>\n<p><p>\u5728Matplotlib\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>ylabel()<\/code>\u51fd\u6570\u4e3ay\u8f74\u8bbe\u7f6e\u6807\u7b7e\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cy\u8f74\u6807\u7b7e\u662f\u5782\u76f4\u663e\u793a\u7684\uff0c\u8fd9\u5bf9\u4e8e\u5927\u591a\u6570\u7eb5\u5411\u56fe\u8868\u6765\u8bf4\u662f\u5408\u9002\u7684\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u5e0c\u671b\u5c06y\u8f74\u6807\u7b7e\u6c34\u5e73\u653e\u7f6e\uff0c\u4ee5\u4fbf\u63d0\u9ad8\u53ef\u8bfb\u6027\u6216\u9002\u5e94\u7279\u5b9a\u7684\u56fe\u8868\u5e03\u5c40\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.ylabel(&#39;Vertical Label&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2\u3001\u6c34\u5e73\u653e\u7f6eYLABEL<\/h2>\n<\/p>\n<p><p>\u8981\u5c06y\u8f74\u6807\u7b7e\u6c34\u5e73\u653e\u7f6e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>rotation<\/code>\u53c2\u6570\u4e3a<code>0<\/code>\u6765\u5b9e\u73b0\u3002\u8fd9\u4f1a\u4f7f\u6807\u7b7e\u4e0ex\u8f74\u5e73\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.ylabel(&#39;Horizontal Label&#39;, rotation=0)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e09\u3001YLABEL\u7684\u8fdb\u4e00\u6b65\u81ea\u5b9a\u4e49<\/strong><\/h2>\n<p><h2>1\u3001\u8c03\u6574YLABEL\u7684\u4f4d\u7f6e<\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u65cb\u8f6c\u6807\u7b7e\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u8c03\u6574\u6807\u7b7e\u4e0e\u8f74\u7684\u8ddd\u79bb\u3002\u901a\u8fc7<code>labelpad<\/code>\u53c2\u6570\u53ef\u4ee5\u589e\u52a0\u6216\u51cf\u5c11\u6807\u7b7e\u4e0ey\u8f74\u4e4b\u95f4\u7684\u7a7a\u9699\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.ylabel(&#39;Horizontal Label&#39;, rotation=0, labelpad=15)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2\u3001\u8bbe\u7f6eYLABEL\u7684\u5b57\u4f53\u5c5e\u6027<\/h2>\n<\/p>\n<p><p>Matplotlib\u5141\u8bb8\u6211\u4eec\u81ea\u5b9a\u4e49\u6807\u7b7e\u7684\u5b57\u4f53\u5c5e\u6027\uff0c\u5305\u62ec\u5b57\u4f53\u5927\u5c0f\u3001\u5b57\u4f53\u989c\u8272\u548c\u5b57\u4f53\u98ce\u683c\u7b49\u3002\u901a\u8fc7\u8bbe\u7f6e\u8fd9\u4e9b\u5c5e\u6027\uff0c\u53ef\u4ee5\u589e\u5f3a\u56fe\u8868\u7684\u89c6\u89c9\u6548\u679c\u548c\u6807\u7b7e\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>plt.ylabel(&#39;Horizontal Label&#39;, rotation=0, fontsize=14, color=&#39;blue&#39;, fontweight=&#39;bold&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u56db\u3001\u5728\u7279\u5b9a\u60c5\u5883\u4e0b\u5e94\u7528\u6c34\u5e73YLABEL<\/strong><\/h2>\n<p><h2>1\u3001\u5728\u591a\u5b50\u56fe\u4e2d\u7684\u5e94\u7528<\/h2>\n<\/p>\n<p><p>\u5728\u591a\u5b50\u56fe\u4e2d\uff0c\u5c06y\u8f74\u6807\u7b7e\u6c34\u5e73\u653e\u7f6e\u53ef\u4ee5\u8282\u7701\u7a7a\u95f4\u5e76\u63d0\u9ad8\u56fe\u8868\u7684\u6574\u6d01\u5ea6\u3002\u901a\u8fc7\u4f7f\u7528<code>subplots()<\/code>\u51fd\u6570\u521b\u5efa\u591a\u4e2a\u5b50\u56fe\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u5b50\u56fe\u5355\u72ec\u8bbe\u7f6ey\u8f74\u6807\u7b7e\u7684\u5c5e\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fig, axs = plt.subplots(2)<\/p>\n<p>axs[0].plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<p>axs[0].set_ylabel(&#39;Horizontal Label&#39;, rotation=0)<\/p>\n<p>axs[1].plot([1, 2, 3, 4], [10, 15, 20, 25])<\/p>\n<p>axs[1].set_ylabel(&#39;Horizontal Label&#39;, rotation=0)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2\u3001\u5728\u7279\u6b8a\u56fe\u5f62\u4e2d\u7684\u5e94\u7528<\/h2>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u7279\u6b8a\u56fe\u5f62\u4e2d\uff0c\u5982\u6781\u5750\u6807\u56fe\u6216\u4e09\u7ef4\u56fe\u5f62\uff0c\u53ef\u80fd\u9700\u8981\u8c03\u6574\u6807\u7b7e\u7684\u65b9\u5411\u4ee5\u9002\u5e94\u56fe\u5f62\u7684\u5e03\u5c40\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5c06y\u8f74\u6807\u7b7e\u6c34\u5e73\u653e\u7f6e\u53ef\u4ee5\u786e\u4fdd\u6807\u7b7e\u7684\u6e05\u6670\u5ea6\u548c\u56fe\u8868\u7684\u7f8e\u89c2\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fig = plt.figure()<\/p>\n<p>ax = fig.add_subplot(111, polar=True)<\/p>\n<p>ax.set_ylabel(&#39;Horizontal Label&#39;, rotation=0, labelpad=20)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e94\u3001YLABEL\u6c34\u5e73\u653e\u7f6e\u7684\u6ce8\u610f\u4e8b\u9879<\/strong><\/h2>\n<p><h2>1\u3001\u4e0e\u56fe\u8868\u98ce\u683c\u7684\u534f\u8c03<\/h2>\n<\/p>\n<p><p>\u5728\u8bbe\u7f6ey\u8f74\u6807\u7b7e\u65f6\uff0c\u5e94\u6ce8\u610f\u4e0e\u6574\u4f53\u56fe\u8868\u98ce\u683c\u7684\u534f\u8c03\uff0c\u5305\u62ec\u6807\u7b7e\u989c\u8272\u3001\u5b57\u4f53\u4ee5\u53ca\u4e0e\u5176\u4ed6\u5143\u7d20\u7684\u5bf9\u9f50\u3002\u786e\u4fddy\u8f74\u6807\u7b7e\u7684\u6837\u5f0f\u4e0e\u56fe\u8868\u6574\u4f53\u98ce\u683c\u4e00\u81f4\uff0c\u4ee5\u907f\u514d\u89c6\u89c9\u4e0a\u7684\u4e0d\u534f\u8c03\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u5bf9\u4e0d\u540c\u6570\u636e\u96c6\u7684\u9002\u7528\u6027<\/h2>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u96c6\u548c\u56fe\u8868\uff0cy\u8f74\u6807\u7b7e\u7684\u8bbe\u7f6e\u53ef\u80fd\u9700\u8981\u8fdb\u884c\u8c03\u6574\u3002\u4f8b\u5982\uff0c\u5728\u67d0\u4e9b\u6570\u636e\u96c6\u4e2d\uff0cy\u8f74\u6807\u7b7e\u53ef\u80fd\u9700\u8981\u66f4\u5927\u7684\u5b57\u4f53\u6216\u66f4\u957f\u7684\u6807\u7b7e\u95f4\u8ddd\uff0c\u4ee5\u63d0\u9ad8\u53ef\u8bfb\u6027\u548c\u7406\u89e3\u6027\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u901a\u8fc7\u4e86\u89e3\u548c\u5e94\u7528\u4e0a\u8ff0\u6280\u5de7\uff0c\u60a8\u53ef\u4ee5\u5728Matplotlib\u4e2d\u7075\u6d3b\u5730\u8bbe\u7f6ey\u8f74\u6807\u7b7e\u7684\u65cb\u8f6c\u89d2\u5ea6\u548c\u4f4d\u7f6e\uff0c\u4ece\u800c\u521b\u5efa\u51fa\u66f4\u5177\u53ef\u8bfb\u6027\u548c\u7f8e\u89c2\u6027\u7684\u56fe\u8868\u3002\u8fd9\u79cd\u81ea\u5b9a\u4e49\u529f\u80fd\u5728\u6570\u636e\u53ef\u89c6\u5316\u8fc7\u7a0b\u4e2d\u975e\u5e38\u91cd\u8981\uff0c\u80fd\u591f\u6709\u6548\u5730\u4f20\u8fbe\u6570\u636e\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06y\u8f74\u6807\u7b7e\u65cb\u8f6c\u4e3a\u6c34\u5e73\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Matplotlib\u7ed8\u5236\u56fe\u5f62\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>ylabel<\/code>\u7684<code>rotation<\/code>\u53c2\u6570\u6765\u5c06y\u8f74\u6807\u7b7e\u65cb\u8f6c\u4e3a\u6c34\u5e73\u3002\u5177\u4f53\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nplt.plot([1, 2, 3], [4, 5, 6])\nplt.ylabel(&#39;Y\u8f74\u6807\u7b7e&#39;, rotation=0)  # \u8bbe\u5b9a\u4e3a0\u5ea6\uff0c\u6807\u7b7e\u5c06\u6c34\u5e73\u663e\u793a\nplt.show()\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u81ea\u5b9a\u4e49y\u8f74\u6807\u7b7e\u7684\u663e\u793a\u89d2\u5ea6\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528Seaborn\u65f6\uff0c\u5982\u4f55\u8bbe\u7f6ey\u8f74\u6807\u7b7e\u4e3a\u6a2a\u5411\uff1f<\/strong><br \/>Seaborn\u662f\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\uff0c\u60a8\u53ef\u4ee5\u5728\u7ed8\u56fe\u540e\u76f4\u63a5\u4f7f\u7528Matplotlib\u7684\u529f\u80fd\u6765\u8c03\u6574y\u8f74\u6807\u7b7e\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import seaborn as sns\nimport matplotlib.pyplot as plt\n\nsns.scatterplot(x=[1, 2, 3], y=[4, 5, 6])\nplt.ylabel(&#39;Y\u8f74\u6807\u7b7e&#39;, rotation=0)  # \u5c06y\u8f74\u6807\u7b7e\u8bbe\u7f6e\u4e3a\u6c34\u5e73\nplt.show()\n<\/code><\/pre>\n<p>\u5728Seaborn\u7ed8\u56fe\u65f6\uff0c\u5229\u7528Matplotlib\u7684\u529f\u80fd\u53ef\u4ee5\u8f7b\u677e\u8c03\u6574y\u8f74\u6807\u7b7e\u7684\u65b9\u5411\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4f7f\u7528LaTeX\u8bed\u6cd5\u6765\u683c\u5f0f\u5316y\u8f74\u6807\u7b7e\uff1f<\/strong><br \/>\u662f\u7684\uff0cMatplotlib\u652f\u6301LaTeX\u8bed\u6cd5\u6765\u683c\u5f0f\u5316\u6807\u7b7e\u5185\u5bb9\u3002\u60a8\u53ef\u4ee5\u5728<code>ylabel<\/code>\u4e2d\u63d2\u5165LaTeX\u4ee3\u7801\uff0c\u540c\u65f6\u8bbe\u7f6e\u6807\u7b7e\u65cb\u8f6c\u4e3a\u6c34\u5e73\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">plt.ylabel(r&#39;$\\alpha + \\beta$&#39;, rotation=0)  # \u4f7f\u7528LaTeX\u8bed\u6cd5\u5e76\u8bbe\u4e3a\u6c34\u5e73\nplt.show()\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u53ef\u4ee5\u8c03\u6574\u6807\u7b7e\u65b9\u5411\uff0c\u8fd8\u80fd\u4f7f\u6807\u7b7e\u5448\u73b0\u66f4\u590d\u6742\u7684\u6570\u5b66\u8868\u8fbe\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Matplotlib\u4e2d\uff0c\u5c06ylabel\u6253\u6a2a\u53ef\u4ee5\u4f7f\u7528labelpad\u53c2\u6570\u8c03\u6574\u6807\u7b7e\u4e0e\u8f74\u7684\u8ddd\u79bb\u3001\u4f7f\u7528rotatio [&hellip;]","protected":false},"author":3,"featured_media":933368,"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\/933363"}],"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=933363"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/933363\/revisions"}],"predecessor-version":[{"id":933369,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/933363\/revisions\/933369"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/933368"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=933363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=933363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=933363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}