{"id":1155801,"date":"2025-01-13T18:08:13","date_gmt":"2025-01-13T10:08:13","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1155801.html"},"modified":"2025-01-13T18:08:16","modified_gmt":"2025-01-13T10:08:16","slug":"python%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89%e7%bb%98%e5%9b%be%e5%8c%ba%e5%9f%9f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1155801.html","title":{"rendered":"python\u5982\u4f55\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25194336\/8e10929f-fc64-4ce6-b69c-6fc158ad5524.webp\" alt=\"python\u5982\u4f55\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df\" \/><\/p>\n<p><p> \u5728Python\u4e2d\uff0c\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df\u5e38\u5e38\u4f7f\u7528\u5230<code>matplotlib<\/code>\u5e93\u3002<strong>\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u5b50\u56fe\u3001\u8bbe\u7f6e\u7ed8\u56fe\u533a\u57df\u7684\u5927\u5c0f\u3001\u4f7f\u7528\u7f51\u683c\u5e03\u5c40\u7b49\u65b9\u5f0f\u6765\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df<\/strong>\u3002\u5176\u4e2d\u4e00\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528<code>plt.subplot<\/code>\u548c<code>plt.subplots<\/code>\u51fd\u6570\u3002\u8fd9\u91cc\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u5b9e\u9645\u7684\u4f8b\u5b50\u6765\u8bf4\u660e\u6bcf\u79cd\u65b9\u6cd5\u7684\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528 <code>plt.figure<\/code> \u548c <code>plt.subplot<\/code> \u5b9a\u4e49\u7ed8\u56fe\u533a\u57df<\/h3>\n<\/p>\n<p><p><code>matplotlib.pyplot.figure<\/code> \u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u50cf\uff0c<code>matplotlib.pyplot.subplot<\/code> \u5219\u53ef\u4ee5\u5728\u4e00\u4e2a\u56fe\u50cf\u4e2d\u521b\u5efa\u591a\u4e2a\u5b50\u56fe\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7075\u6d3b\u5730\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df\u5e76\u5728\u540c\u4e00\u4e2a\u56fe\u50cf\u4e2d\u5c55\u793a\u591a\u4e2a\u56fe\u8868\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u56fe\u50cf<\/strong><\/h2>\n<p>fig = plt.figure(figsize=(10, 6))<\/p>\n<h2><strong>\u5728\u56fe\u50cf\u4e2d\u6dfb\u52a0\u5b50\u56fe<\/strong><\/h2>\n<p>ax1 = fig.add_subplot(2, 2, 1)  # 2\u884c2\u5217\u7684\u7f51\u683c\uff0c\u7b2c\u4e00\u5b50\u56fe<\/p>\n<p>ax2 = fig.add_subplot(2, 2, 2)  # 2\u884c2\u5217\u7684\u7f51\u683c\uff0c\u7b2c\u4e8c\u5b50\u56fe<\/p>\n<p>ax3 = fig.add_subplot(2, 2, 3)  # 2\u884c2\u5217\u7684\u7f51\u683c\uff0c\u7b2c\u4e09\u5b50\u56fe<\/p>\n<p>ax4 = fig.add_subplot(2, 2, 4)  # 2\u884c2\u5217\u7684\u7f51\u683c\uff0c\u7b2c\u56db\u5b50\u56fe<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax1.plot([1, 2, 3], [1, 4, 9])<\/p>\n<p>ax2.plot([1, 2, 3], [1, 2, 3])<\/p>\n<p>ax3.plot([1, 2, 3], [9, 4, 1])<\/p>\n<p>ax4.plot([1, 2, 3], [1, 3, 2])<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>plt.tight_layout()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<strong><code>fig.add_subplot(2, 2, 1)<\/code>\u8868\u793a\u5728\u4e00\u4e2a2\u884c2\u5217\u7684\u7f51\u683c\u4e2d\u6dfb\u52a0\u7b2c\u4e00\u4e2a\u5b50\u56fe<\/strong>\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u56fe\u50cf\u4e2d\u5b9a\u4e49\u591a\u4e2a\u7ed8\u56fe\u533a\u57df\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528 <code>plt.subplots<\/code> \u5b9a\u4e49\u7ed8\u56fe\u533a\u57df<\/h3>\n<\/p>\n<p><p><code>plt.subplots<\/code> \u662f\u4e00\u4e2a\u66f4\u4e3a\u7b80\u6d01\u548c\u5e38\u7528\u7684\u65b9\u6cd5\u6765\u521b\u5efa\u5b50\u56fe\u3002\u5b83\u53ef\u4ee5\u540c\u65f6\u521b\u5efa\u4e00\u4e2a\u56fe\u50cf\u548c\u591a\u4e2a\u5b50\u56fe\uff0c\u5e76\u8fd4\u56de\u56fe\u50cf\u5bf9\u8c61\u548c\u5b50\u56fe\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u56fe\u50cf\u548c\u5b50\u56fe<\/strong><\/h2>\n<p>fig, axs = plt.subplots(2, 2, figsize=(10, 6))<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>axs[0, 0].plot([1, 2, 3], [1, 4, 9])<\/p>\n<p>axs[0, 1].plot([1, 2, 3], [1, 2, 3])<\/p>\n<p>axs[1, 0].plot([1, 2, 3], [9, 4, 1])<\/p>\n<p>axs[1, 1].plot([1, 2, 3], [1, 3, 2])<\/p>\n<h2><strong>\u8c03\u6574\u5e03\u5c40<\/strong><\/h2>\n<p>plt.tight_layout()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<strong><code>plt.subplots(2, 2, figsize=(10, 6))<\/code>\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b2\u884c2\u5217\u5b50\u56fe\u7684\u56fe\u50cf\uff0c\u5e76\u8bbe\u7f6e\u56fe\u50cf\u7684\u5927\u5c0f\u4e3a10&#215;6\u82f1\u5bf8<\/strong>\u3002\u901a\u8fc7\u8bbf\u95ee<code>axs<\/code>\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u5728\u5404\u4e2a\u5b50\u56fe\u4e2d\u7ed8\u5236\u4e0d\u540c\u7684\u56fe\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528 <code>GridSpec<\/code> \u5b9a\u4e49\u590d\u6742\u5e03\u5c40<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u52a0\u590d\u6742\u7684\u5e03\u5c40\uff0c\u53ef\u4ee5\u4f7f\u7528<code>matplotlib.gridspec.GridSpec<\/code>\u3002\u5b83\u5141\u8bb8\u5728\u4e00\u4e2a\u56fe\u50cf\u4e2d\u521b\u5efa\u4efb\u610f\u5927\u5c0f\u548c\u4f4d\u7f6e\u7684\u5b50\u56fe\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/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\u4e00\u4e2a\u56fe\u50cf<\/strong><\/h2>\n<p>fig = plt.figure(figsize=(10, 6))<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aGridSpec\u5bf9\u8c61<\/strong><\/h2>\n<p>gs = gridspec.GridSpec(3, 3)<\/p>\n<h2><strong>\u5728GridSpec\u4e2d\u6dfb\u52a0\u5b50\u56fe<\/strong><\/h2>\n<p>ax1 = fig.add_subplot(gs[0, :])   # \u7b2c\u4e00\u884c<\/p>\n<p>ax2 = fig.add_subplot(gs[1, :-1]) # \u7b2c\u4e8c\u884c\u524d\u4e24\u5217<\/p>\n<p>ax3 = fig.add_subplot(gs[1:, -1]) # \u7b2c\u4e8c\u884c\u548c\u7b2c\u4e09\u884c\u7684\u6700\u540e\u4e00\u5217<\/p>\n<p>ax4 = fig.add_subplot(gs[-1, 0])  # \u7b2c\u4e09\u884c\u7b2c\u4e00\u5217<\/p>\n<p>ax5 = fig.add_subplot(gs[-1, -2]) # \u7b2c\u4e09\u884c\u7b2c\u4e8c\u5217<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax1.plot([1, 2, 3], [1, 4, 9])<\/p>\n<p>ax2.plot([1, 2, 3], [1, 2, 3])<\/p>\n<p>ax3.plot([1, 2, 3], [9, 4, 1])<\/p>\n<p>ax4.plot([1, 2, 3], [1, 3, 2])<\/p>\n<p>ax5.plot([1, 2, 3], [2, 3, 1])<\/p>\n<h2><strong>\u8c03\u6574\u5e03\u5c40<\/strong><\/h2>\n<p>plt.tight_layout()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<strong><code>GridSpec<\/code>\u5bf9\u8c61\u5141\u8bb8\u6211\u4eec\u5b9a\u4e49\u4efb\u610f\u5927\u5c0f\u548c\u4f4d\u7f6e\u7684\u5b50\u56fe<\/strong>\u3002\u4f8b\u5982\uff0c<code>gs[0, :]<\/code>\u8868\u793a\u7b2c\u4e00\u884c\u7684\u6240\u6709\u5217\uff0c<code>gs[1, :-1]<\/code>\u8868\u793a\u7b2c\u4e8c\u884c\u7684\u524d\u4e24\u5217\uff0c<code>gs[1:, -1]<\/code>\u8868\u793a\u7b2c\u4e8c\u884c\u548c\u7b2c\u4e09\u884c\u7684\u6700\u540e\u4e00\u5217\uff0c\u7b49\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u8bbe\u7f6e\u5b50\u56fe\u95f4\u8ddd\u548c\u8fb9\u8ddd<\/h3>\n<\/p>\n<p><p>\u5728\u591a\u5b50\u56fe\u5e03\u5c40\u4e2d\uff0c\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\u548c\u56fe\u50cf\u7684\u8fb9\u8ddd\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u53ef\u4ee5\u4f7f\u7528<code>plt.subplots_adjust<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u56fe\u50cf\u548c\u5b50\u56fe<\/strong><\/h2>\n<p>fig, axs = plt.subplots(2, 2, figsize=(10, 6))<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>axs[0, 0].plot([1, 2, 3], [1, 4, 9])<\/p>\n<p>axs[0, 1].plot([1, 2, 3], [1, 2, 3])<\/p>\n<p>axs[1, 0].plot([1, 2, 3], [9, 4, 1])<\/p>\n<p>axs[1, 1].plot([1, 2, 3], [1, 3, 2])<\/p>\n<h2><strong>\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd\u548c\u56fe\u50cf\u8fb9\u8ddd<\/strong><\/h2>\n<p>plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1, hspace=0.4, wspace=0.4)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<strong><code>plt.subplots_adjust<\/code>\u51fd\u6570\u53ef\u4ee5\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u6c34\u5e73\u548c\u5782\u76f4\u95f4\u8ddd\uff08<code>hspace<\/code>\u548c<code>wspace<\/code>\uff09\uff0c\u4ee5\u53ca\u56fe\u50cf\u7684\u5de6\u53f3\u3001\u4e0a\u4e0b\u8fb9\u8ddd\uff08<code>left<\/code>\u3001<code>right<\/code>\u3001<code>top<\/code>\u3001<code>bottom<\/code>\uff09<\/strong>\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528 <code>Axes<\/code> \u5bf9\u8c61\u81ea\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u66f4\u52a0\u7075\u6d3b\u5730\u81ea\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df\u7684\u4f4d\u7f6e\u548c\u5927\u5c0f\u3002\u8fd9\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>matplotlib.axes.Axes<\/code>\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u56fe\u50cf<\/strong><\/h2>\n<p>fig = plt.figure(figsize=(10, 6))<\/p>\n<h2><strong>\u81ea\u5b9a\u4e49\u5b50\u56fe\u7684\u4f4d\u7f6e\u548c\u5927\u5c0f\uff08\u5de6\uff0c\u4e0b\uff0c\u5bbd\uff0c\u9ad8\uff09<\/strong><\/h2>\n<p>ax1 = fig.add_axes([0.1, 0.6, 0.35, 0.35])<\/p>\n<p>ax2 = fig.add_axes([0.55, 0.6, 0.35, 0.35])<\/p>\n<p>ax3 = fig.add_axes([0.1, 0.1, 0.35, 0.35])<\/p>\n<p>ax4 = fig.add_axes([0.55, 0.1, 0.35, 0.35])<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax1.plot([1, 2, 3], [1, 4, 9])<\/p>\n<p>ax2.plot([1, 2, 3], [1, 2, 3])<\/p>\n<p>ax3.plot([1, 2, 3], [9, 4, 1])<\/p>\n<p>ax4.plot([1, 2, 3], [1, 3, 2])<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<strong><code>fig.add_axes([left, bottom, width, height])<\/code>\u51fd\u6570\u5141\u8bb8\u6211\u4eec\u81ea\u5b9a\u4e49\u6bcf\u4e2a\u5b50\u56fe\u7684\u4f4d\u7f6e\u548c\u5927\u5c0f<\/strong>\u3002\u5de6\u3001\u4e0b\u3001\u5bbd\u3001\u9ad8\u7684\u503c\u662f\u76f8\u5bf9\u4e8e\u56fe\u50cf\u7684\u6bd4\u4f8b\uff080\u52301\u4e4b\u95f4\uff09\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528 <code>plt.GridSpecFromSubplotSpec<\/code> \u5d4c\u5957\u5b50\u56fe<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u5728\u4e00\u4e2a\u5b50\u56fe\u4e2d\u518d\u5d4c\u5957\u5b50\u56fe\uff0c\u8fd9\u65f6\u53ef\u4ee5\u4f7f\u7528<code>GridSpecFromSubplotSpec<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/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\u4e00\u4e2a\u56fe\u50cf<\/strong><\/h2>\n<p>fig = plt.figure(figsize=(10, 6))<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aGridSpec\u5bf9\u8c61<\/strong><\/h2>\n<p>outer_gs = gridspec.GridSpec(2, 1)<\/p>\n<h2><strong>\u5728GridSpec\u4e2d\u6dfb\u52a0\u5b50\u56fe<\/strong><\/h2>\n<p>ax1 = fig.add_subplot(outer_gs[0])<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5d4c\u5957\u7684GridSpec\u5bf9\u8c61<\/strong><\/h2>\n<p>inner_gs = gridspec.GridSpecFromSubplotSpec(1, 2, subplot_spec=outer_gs[1])<\/p>\n<h2><strong>\u5728\u5d4c\u5957\u7684GridSpec\u4e2d\u6dfb\u52a0\u5b50\u56fe<\/strong><\/h2>\n<p>ax2 = fig.add_subplot(inner_gs[0])<\/p>\n<p>ax3 = fig.add_subplot(inner_gs[1])<\/p>\n<h2><strong>\u7ed8\u5236\u56fe\u8868<\/strong><\/h2>\n<p>ax1.plot([1, 2, 3], [1, 4, 9])<\/p>\n<p>ax2.plot([1, 2, 3], [1, 2, 3])<\/p>\n<p>ax3.plot([1, 2, 3], [9, 4, 1])<\/p>\n<h2><strong>\u8c03\u6574\u5e03\u5c40<\/strong><\/h2>\n<p>plt.tight_layout()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<strong>\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a2\u884c1\u5217\u7684\u5916\u90e8<code>GridSpec<\/code>\u5bf9\u8c61<code>outer_gs<\/code>\uff0c\u7136\u540e\u5728\u7b2c\u4e8c\u884c\u4e2d\u518d\u5d4c\u5957\u4e00\u4e2a1\u884c2\u5217\u7684\u5185\u90e8<code>GridSpec<\/code>\u5bf9\u8c61<code>inner_gs<\/code><\/strong>\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728\u4e00\u4e2a\u56fe\u50cf\u4e2d\u521b\u5efa\u66f4\u52a0\u590d\u6742\u548c\u7075\u6d3b\u7684\u5e03\u5c40\u3002<\/p>\n<\/p>\n<p><h3>\u5c0f\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u51e0\u79cd\u65b9\u6cd5\uff0c<strong>\u53ef\u4ee5\u5728Python\u4e2d\u7075\u6d3b\u5730\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df<\/strong>\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u5b50\u56fe\u5e03\u5c40\u8fd8\u662f\u590d\u6742\u7684\u5d4c\u5957\u5e03\u5c40\uff0c\u90fd\u53ef\u4ee5\u901a\u8fc7<code>matplotlib<\/code>\u5e93\u8f7b\u677e\u5b9e\u73b0\u3002<strong>\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u4e0d\u4ec5\u53ef\u4ee5\u63d0\u9ad8\u7ed8\u56fe\u7684\u6548\u7387\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u56fe\u50cf\u66f4\u52a0\u6e05\u6670\u548c\u7f8e\u89c2<\/strong>\u3002\u5e0c\u671b\u8fd9\u4e9b\u4f8b\u5b50\u548c\u89e3\u91ca\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u9009\u62e9\u7ed8\u56fe\u533a\u57df\u7684\u5927\u5c0f\u548c\u6bd4\u4f8b\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528Matplotlib\u5e93\u53ef\u4ee5\u8f7b\u677e\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df\u7684\u5927\u5c0f\u548c\u6bd4\u4f8b\u3002\u53ef\u4ee5\u4f7f\u7528<code>plt.figure(figsize=(width, height))<\/code>\u6765\u8bbe\u7f6e\u7ed8\u56fe\u533a\u57df\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff0c\u5355\u4f4d\u4e3a\u82f1\u5bf8\u3002\u540c\u65f6\uff0c\u901a\u8fc7<code>plt.axis(&#39;equal&#39;)<\/code>\u6765\u786e\u4fddX\u8f74\u548cY\u8f74\u7684\u6bd4\u4f8b\u76f8\u540c\uff0c\u4fbf\u4e8e\u5c55\u793a\u6570\u636e\u7684\u771f\u5b9e\u5173\u7cfb\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>plt.xlim()<\/code>\u548c<code>plt.ylim()<\/code>\u6765\u9650\u5236X\u8f74\u548cY\u8f74\u7684\u8303\u56f4\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u805a\u7126\u4e8e\u611f\u5174\u8da3\u7684\u533a\u57df\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9b\u5e93\u6765\u5b9a\u4e49\u548c\u63a7\u5236\u7ed8\u56fe\u533a\u57df\uff1f<\/strong><br \/>\u9664\u4e86Matplotlib\uff0cPython\u4e2d\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u5e93\u53ef\u4ee5\u7528\u6765\u5b9a\u4e49\u548c\u63a7\u5236\u7ed8\u56fe\u533a\u57df\u3002\u4f8b\u5982\uff0cSeaborn\u662f\u57fa\u4e8eMatplotlib\u6784\u5efa\u7684\u9ad8\u7ea7\u53ef\u89c6\u5316\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u7f8e\u89c2\u7684\u7ed8\u56fe\u98ce\u683c\u548c\u7b80\u5316\u7684\u63a5\u53e3\u3002\u6b64\u5916\uff0cPlotly\u4e5f\u5141\u8bb8\u7528\u6237\u521b\u5efa\u4ea4\u4e92\u5f0f\u56fe\u8868\uff0c\u80fd\u591f\u66f4\u7075\u6d3b\u5730\u8c03\u6574\u7ed8\u56fe\u533a\u57df\u548c\u89c6\u56fe\u8bbe\u7f6e\u3002\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u548c\u4e2a\u4eba\u504f\u597d\u6765\u51b3\u5b9a\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u591a\u4e2a\u7ed8\u56fe\u533a\u57df\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u7684<code>plt.subplots()<\/code>\u51fd\u6570\u6765\u521b\u5efa\u591a\u4e2a\u7ed8\u56fe\u533a\u57df\u3002\u901a\u8fc7\u6307\u5b9a\u884c\u6570\u548c\u5217\u6570\uff0c\u53ef\u4ee5\u751f\u6210\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62\u3002\u4f8b\u5982\uff0c<code>fig, axs = plt.subplots(nrows=2, ncols=2)<\/code>\u5c06\u521b\u5efa\u4e00\u4e2a2&#215;2\u7684\u7ed8\u56fe\u7f51\u683c\u3002\u6bcf\u4e2a\u5b50\u56fe\u90fd\u53ef\u4ee5\u5355\u72ec\u5b9a\u4e49\u5176\u6570\u636e\u548c\u6837\u5f0f\uff0c\u8fd9\u6837\u7528\u6237\u53ef\u4ee5\u5728\u540c\u4e00\u56fe\u5f62\u4e2d\u5c55\u793a\u4e0d\u540c\u7684\u6570\u636e\u96c6\u6216\u5bf9\u6bd4\u5206\u6790\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u5b9a\u4e49\u7ed8\u56fe\u533a\u57df\u5e38\u5e38\u4f7f\u7528\u5230matplotlib\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u5b50\u56fe\u3001\u8bbe\u7f6e\u7ed8\u56fe\u533a\u57df\u7684\u5927\u5c0f\u3001\u4f7f\u7528\u7f51\u683c [&hellip;]","protected":false},"author":3,"featured_media":1155803,"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\/1155801"}],"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=1155801"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155801\/revisions"}],"predecessor-version":[{"id":1155804,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155801\/revisions\/1155804"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1155803"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1155801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1155801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1155801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}