{"id":1136668,"date":"2025-01-08T21:38:43","date_gmt":"2025-01-08T13:38:43","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1136668.html"},"modified":"2025-01-08T21:38:46","modified_gmt":"2025-01-08T13:38:46","slug":"python-%e5%a6%82%e4%bd%95%e8%b0%83%e6%95%b4%e4%b8%a4%e4%b8%aa%e5%9b%be%e5%be%97%e5%9e%82%e7%9b%b4%e8%b7%9d%e7%a6%bb","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1136668.html","title":{"rendered":"python \u5982\u4f55\u8c03\u6574\u4e24\u4e2a\u56fe\u5f97\u5782\u76f4\u8ddd\u79bb"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25100714\/0d5766d1-c9e2-4fcb-b6d7-6be85ee6662b.webp\" alt=\"python \u5982\u4f55\u8c03\u6574\u4e24\u4e2a\u56fe\u5f97\u5782\u76f4\u8ddd\u79bb\" \/><\/p>\n<p><h3>\u4e00\u3001\u76f4\u63a5\u8c03\u6574\u56fe\u8868\u95f4\u5782\u76f4\u8ddd\u79bb\u7684\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><strong>\u5728Python\u4e2d\u8c03\u6574\u4e24\u4e2a\u56fe\u8868\u7684\u5782\u76f4\u8ddd\u79bb\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574subplot\u53c2\u6570\u3001\u8bbe\u7f6e\u56fe\u8868\u7684Figure\u5c3a\u5bf8\u3001\u8c03\u6574\u56fe\u8868\u7684\u5b50\u56fe\u95f4\u8ddd\u7b49\u65b9\u6cd5\u6765\u5b9e\u73b0<\/strong>\u3002\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u662f\u901a\u8fc7<code>matplotlib<\/code>\u5e93\u4e2d\u7684<code>subplots_adjust<\/code>\u51fd\u6570\u6765\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002\u901a\u8fc7\u8c03\u6574\u8fd9\u4e9b\u53c2\u6570\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u63a7\u5236\u4e24\u4e2a\u56fe\u8868\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\uff0c\u4ee5\u8fbe\u5230\u6700\u4f73\u7684\u53ef\u89c6\u5316\u6548\u679c\u3002<strong>\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528<code>subplots_adjust<\/code>\u51fd\u6570\u6765\u8c03\u6574\u56fe\u8868\u95f4\u8ddd<\/strong>\u3002<\/p>\n<\/p>\n<p><p><code>matplotlib<\/code> \u662f Python \u4e2d\u7528\u4e8e\u7ed8\u5236\u56fe\u8868\u7684\u5e38\u7528\u5e93\u3002\u8981\u8c03\u6574\u4e24\u4e2a\u56fe\u8868\u7684\u5782\u76f4\u8ddd\u79bb\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62\uff0c\u7136\u540e\u4f7f\u7528 <code>subplots_adjust<\/code> \u51fd\u6570\u6765\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u5305\u542b\u591a\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62<\/strong>\uff1a\u4f7f\u7528 <code>plt.subplots<\/code> \u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62\u3002<\/li>\n<li><strong>\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd<\/strong>\uff1a\u4f7f\u7528 <code>plt.subplots_adjust<\/code> \u51fd\u6570\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002<\/li>\n<\/ol>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u6765\u8c03\u6574\u4e24\u4e2a\u56fe\u8868\u7684\u5782\u76f4\u8ddd\u79bb\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u5305\u542b\u4e24\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62<\/strong><\/h2>\n<p>fig, (ax1, ax2) = plt.subplots(2, 1)<\/p>\n<h2><strong>\u5728\u7b2c\u4e00\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax1.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>ax1.set_title(&#39;First Plot&#39;)<\/p>\n<h2><strong>\u5728\u7b2c\u4e8c\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax2.plot([1, 2, 3], [6, 5, 4])<\/p>\n<p>ax2.set_title(&#39;Second Plot&#39;)<\/p>\n<h2><strong>\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb<\/strong><\/h2>\n<p>plt.subplots_adjust(hspace=0.5)<\/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\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>plt.subplots_adjust(hspace=0.5)<\/code> \u7528\u4e8e\u8c03\u6574\u4e24\u4e2a\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\u3002<code>hspace<\/code> \u53c2\u6570\u63a7\u5236\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\uff0c\u9ed8\u8ba4\u503c\u4e3a0.2\u3002\u901a\u8fc7\u589e\u52a0 <code>hspace<\/code> \u53c2\u6570\u7684\u503c\uff0c\u53ef\u4ee5\u589e\u52a0\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\uff1b\u53cd\u4e4b\uff0c\u901a\u8fc7\u51cf\u5c0f <code>hspace<\/code> \u53c2\u6570\u7684\u503c\uff0c\u53ef\u4ee5\u51cf\u5c0f\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528 Figure \u548c Axes \u5bf9\u8c61\u8c03\u6574\u56fe\u8868\u95f4\u8ddd<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528 <code>matplotlib<\/code> \u5e93\u7ed8\u5236\u56fe\u8868\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7 Figure \u548c Axes \u5bf9\u8c61\u66f4\u7ec6\u7c92\u5ea6\u5730\u63a7\u5236\u56fe\u8868\u95f4\u8ddd\u3002\u9664\u4e86 <code>subplots_adjust<\/code> \u51fd\u6570\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528 <code>fig.tight_layout<\/code> \u51fd\u6570\u81ea\u52a8\u8c03\u6574\u5b50\u56fe\u95f4\u8ddd\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528 fig.tight_layout \u51fd\u6570<\/h4>\n<\/p>\n<p><p><code>fig.tight_layout<\/code> \u51fd\u6570\u53ef\u4ee5\u81ea\u52a8\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\uff0c\u4ee5\u907f\u514d\u5b50\u56fe\u4e4b\u95f4\u7684\u91cd\u53e0\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u5305\u542b\u4e24\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62<\/strong><\/h2>\n<p>fig, (ax1, ax2) = plt.subplots(2, 1)<\/p>\n<h2><strong>\u5728\u7b2c\u4e00\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax1.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>ax1.set_title(&#39;First Plot&#39;)<\/p>\n<h2><strong>\u5728\u7b2c\u4e8c\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax2.plot([1, 2, 3], [6, 5, 4])<\/p>\n<p>ax2.set_title(&#39;Second Plot&#39;)<\/p>\n<h2><strong>\u81ea\u52a8\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd<\/strong><\/h2>\n<p>fig.tight_layout()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>fig.tight_layout<\/code> \u51fd\u6570\u4f1a\u81ea\u52a8\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\uff0c\u4ee5\u907f\u514d\u5b50\u56fe\u4e4b\u95f4\u7684\u91cd\u53e0\u3002\u8fd9\u5728\u7ed8\u5236\u590d\u6742\u56fe\u8868\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528 GridSpec \u8c03\u6574\u5b50\u56fe\u5e03\u5c40<\/h4>\n<\/p>\n<p><p><code>GridSpec<\/code> \u662f <code>matplotlib<\/code> \u4e2d\u7684\u4e00\u4e2a\u6a21\u5757\uff0c\u7528\u4e8e\u521b\u5efa\u590d\u6742\u7684\u5b50\u56fe\u5e03\u5c40\u3002\u4f7f\u7528 <code>GridSpec<\/code> \u53ef\u4ee5\u66f4\u7075\u6d3b\u5730\u63a7\u5236\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.gridspec as gridspec<\/p>\n<h2><strong>\u521b\u5efa\u5305\u542b\u4e24\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62<\/strong><\/h2>\n<p>fig = plt.figure()<\/p>\n<p>gs = gridspec.GridSpec(2, 1)<\/p>\n<h2><strong>\u5728\u7b2c\u4e00\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax1 = fig.add_subplot(gs[0, 0])<\/p>\n<p>ax1.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>ax1.set_title(&#39;First Plot&#39;)<\/p>\n<h2><strong>\u5728\u7b2c\u4e8c\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax2 = fig.add_subplot(gs[1, 0])<\/p>\n<p>ax2.plot([1, 2, 3], [6, 5, 4])<\/p>\n<p>ax2.set_title(&#39;Second Plot&#39;)<\/p>\n<h2><strong>\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb<\/strong><\/h2>\n<p>gs.update(hspace=0.5)<\/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\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>gs.update(hspace=0.5)<\/code> \u7528\u4e8e\u8c03\u6574\u4e24\u4e2a\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\u3002<code>GridSpec<\/code> \u6a21\u5757\u63d0\u4f9b\u4e86\u66f4\u7075\u6d3b\u7684\u5b50\u56fe\u5e03\u5c40\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u521b\u5efa\u590d\u6742\u7684\u5b50\u56fe\u5e03\u5c40\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5176\u4ed6\u53c2\u6570\u8c03\u6574\u56fe\u8868\u95f4\u8ddd<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u65b9\u6cd5\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u5176\u4ed6\u53c2\u6570\u6765\u63a7\u5236\u56fe\u8868\u95f4\u8ddd\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u8c03\u6574\u56fe\u5f62\u7684\u5c3a\u5bf8\u3001\u5b50\u56fe\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8c03\u6574\u56fe\u5f62\u5c3a\u5bf8<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u8c03\u6574\u56fe\u5f62\u7684\u5c3a\u5bf8\uff0c\u53ef\u4ee5\u95f4\u63a5\u63a7\u5236\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u5305\u542b\u4e24\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62\uff0c\u5e76\u8bbe\u7f6e\u56fe\u5f62\u5c3a\u5bf8<\/strong><\/h2>\n<p>fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 6))<\/p>\n<h2><strong>\u5728\u7b2c\u4e00\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax1.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>ax1.set_title(&#39;First Plot&#39;)<\/p>\n<h2><strong>\u5728\u7b2c\u4e8c\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax2.plot([1, 2, 3], [6, 5, 4])<\/p>\n<p>ax2.set_title(&#39;Second Plot&#39;)<\/p>\n<h2><strong>\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb<\/strong><\/h2>\n<p>plt.subplots_adjust(hspace=0.5)<\/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\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u901a\u8fc7\u8bbe\u7f6e <code>figsize<\/code> \u53c2\u6570\uff0c\u53ef\u4ee5\u8c03\u6574\u56fe\u5f62\u7684\u5c3a\u5bf8\u3002\u901a\u8fc7\u589e\u52a0\u56fe\u5f62\u7684\u9ad8\u5ea6\uff0c\u53ef\u4ee5\u589e\u52a0\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8c03\u6574\u5b50\u56fe\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u8c03\u6574\u5b50\u56fe\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\uff0c\u53ef\u4ee5\u66f4\u7ec6\u7c92\u5ea6\u5730\u63a7\u5236\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u5305\u542b\u4e24\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62<\/strong><\/h2>\n<p>fig, (ax1, ax2) = plt.subplots(2, 1, gridspec_kw={&#39;height_ratios&#39;: [1, 2]})<\/p>\n<h2><strong>\u5728\u7b2c\u4e00\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax1.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>ax1.set_title(&#39;First Plot&#39;)<\/p>\n<h2><strong>\u5728\u7b2c\u4e8c\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax2.plot([1, 2, 3], [6, 5, 4])<\/p>\n<p>ax2.set_title(&#39;Second Plot&#39;)<\/p>\n<h2><strong>\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb<\/strong><\/h2>\n<p>plt.subplots_adjust(hspace=0.5)<\/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\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u901a\u8fc7\u8bbe\u7f6e <code>gridspec_kw<\/code> \u53c2\u6570\uff0c\u53ef\u4ee5\u8c03\u6574\u5b50\u56fe\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u3002\u901a\u8fc7\u8c03\u6574 <code>height_ratios<\/code> \u53c2\u6570\uff0c\u53ef\u4ee5\u63a7\u5236\u6bcf\u4e2a\u5b50\u56fe\u7684\u9ad8\u5ea6\u6bd4\u4f8b\uff0c\u4ece\u800c\u95f4\u63a5\u63a7\u5236\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728Python\u4e2d\u7075\u6d3b\u5730\u8c03\u6574\u4e24\u4e2a\u56fe\u8868\u7684\u5782\u76f4\u8ddd\u79bb\u3002<strong>\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528<code>subplots_adjust<\/code>\u51fd\u6570\u8c03\u6574\u5b50\u56fe\u95f4\u8ddd\u3001\u4f7f\u7528Figure\u548cAxes\u5bf9\u8c61\u66f4\u7ec6\u7c92\u5ea6\u5730\u63a7\u5236\u56fe\u8868\u95f4\u8ddd\u3001\u4f7f\u7528<code>GridSpec<\/code>\u6a21\u5757\u521b\u5efa\u590d\u6742\u7684\u5b50\u56fe\u5e03\u5c40\u3001\u8c03\u6574\u56fe\u5f62\u5c3a\u5bf8\u4ee5\u53ca\u8c03\u6574\u5b50\u56fe\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6<\/strong>\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42\uff0c\u53ef\u4ee5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u6765\u8c03\u6574\u56fe\u8868\u95f4\u8ddd\uff0c\u4ee5\u8fbe\u5230\u6700\u4f73\u7684\u53ef\u89c6\u5316\u6548\u679c\u3002<\/p>\n<\/p>\n<p><p>\u8c03\u6574\u56fe\u8868\u95f4\u8ddd\u7684\u6280\u5de7\u4e0d\u4ec5\u9002\u7528\u4e8e\u7b80\u5355\u7684\u56fe\u8868\u7ed8\u5236\uff0c\u4e5f\u9002\u7528\u4e8e\u590d\u6742\u7684\u53ef\u89c6\u5316\u9879\u76ee\u3002\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u6570\u636e\u53ef\u89c6\u5316\u8fc7\u7a0b\u4e2d\uff0c\u66f4\u597d\u5730\u5c55\u793a\u6570\u636e\uff0c\u4f20\u8fbe\u4fe1\u606f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u4e24\u4e2a\u56fe\u5f62\u7684\u5782\u76f4\u8ddd\u79bb\u8c03\u6574\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u7ed8\u5236\u56fe\u5f62\u5e76\u8c03\u6574\u5b83\u4eec\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\u3002\u901a\u8fc7\u8bbe\u7f6e\u5b50\u56fe\u7684\u53c2\u6570\uff0c\u4f8b\u5982<code>subplots_adjust()<\/code>\u51fd\u6570\u4e2d\u7684<code>hspace<\/code>\u53c2\u6570\uff0c\u53ef\u4ee5\u8f7b\u677e\u63a7\u5236\u56fe\u5f62\u4e4b\u95f4\u7684\u95f4\u9694\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>GridSpec<\/code>\u5e03\u5c40\u4e5f\u80fd\u7075\u6d3b\u5730\u8c03\u6574\u56fe\u5f62\u4e4b\u95f4\u7684\u95f4\u8ddd\u3002<\/p>\n<p><strong>\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5728Matplotlib\u4e2d\u8bbe\u7f6e\u5b50\u56fe\u7684\u5782\u76f4\u95f4\u8ddd\uff1f<\/strong><br \/>Matplotlib\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u8bbe\u7f6e\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u95f4\u8ddd\u3002\u4f7f\u7528<code>plt.subplots()<\/code>\u521b\u5efa\u5b50\u56fe\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>fig.subplots_adjust(hspace=value)<\/code>\u6765\u8c03\u6574\u95f4\u9694\u3002\u53e6\u4e00\u4e2a\u9009\u9879\u662f\u4f7f\u7528<code>GridSpec<\/code>\uff0c\u5b83\u5141\u8bb8\u66f4\u7ec6\u81f4\u7684\u5e03\u5c40\u63a7\u5236\uff0c\u53ef\u4ee5\u901a\u8fc7<code>gs.update(hspace=value)<\/code>\u6765\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\u3002<\/p>\n<p><strong>\u5728\u8c03\u6574\u56fe\u5f62\u95f4\u8ddd\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u5728\u8c03\u6574\u56fe\u5f62\u95f4\u8ddd\u65f6\uff0c\u9700\u8003\u8651\u56fe\u5f62\u7684\u53ef\u8bfb\u6027\u548c\u7f8e\u89c2\u6027\u3002\u8fc7\u5927\u7684\u95f4\u8ddd\u53ef\u80fd\u5bfc\u81f4\u4fe1\u606f\u7684\u5206\u6563\uff0c\u800c\u8fc7\u5c0f\u7684\u95f4\u8ddd\u53c8\u53ef\u80fd\u4f7f\u5f97\u56fe\u5f62\u91cd\u53e0\uff0c\u4ece\u800c\u5f71\u54cd\u6570\u636e\u7684\u5c55\u793a\u6548\u679c\u3002\u6b64\u5916\uff0c\u8fd8\u8981\u786e\u4fdd\u5750\u6807\u8f74\u6807\u7b7e\u3001\u6807\u9898\u548c\u56fe\u4f8b\u7b49\u5143\u7d20\u4e0d\u4f1a\u88ab\u88c1\u526a\uff0c\u4fdd\u6301\u6574\u4f53\u5e03\u5c40\u7684\u6574\u6d01\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001\u76f4\u63a5\u8c03\u6574\u56fe\u8868\u95f4\u5782\u76f4\u8ddd\u79bb\u7684\u65b9\u6cd5 \u5728Python\u4e2d\u8c03\u6574\u4e24\u4e2a\u56fe\u8868\u7684\u5782\u76f4\u8ddd\u79bb\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574subplot\u53c2\u6570\u3001\u8bbe\u7f6e [&hellip;]","protected":false},"author":3,"featured_media":1136674,"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\/1136668"}],"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=1136668"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1136668\/revisions"}],"predecessor-version":[{"id":1136679,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1136668\/revisions\/1136679"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1136674"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1136668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1136668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1136668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}