{"id":977459,"date":"2024-12-27T06:29:43","date_gmt":"2024-12-26T22:29:43","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/977459.html"},"modified":"2024-12-27T06:29:46","modified_gmt":"2024-12-26T22:29:46","slug":"python%e5%a6%82%e4%bd%95%e5%85%b3%e9%97%ad%e6%89%80%e6%9c%89figure","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/977459.html","title":{"rendered":"python\u5982\u4f55\u5173\u95ed\u6240\u6709figure"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24202723\/200c6d68-5b1c-4bcd-8eb3-8b49326b571e.webp\" alt=\"python\u5982\u4f55\u5173\u95ed\u6240\u6709figure\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>matplotlib.pyplot.close(&#39;all&#39;)<\/code>\u5173\u95ed\u6240\u6709figure\u3001\u786e\u4fdd\u4e0d\u5fc5\u8981\u7684\u5185\u5b58\u5360\u7528\u3001\u63d0\u9ad8\u7a0b\u5e8f\u8fd0\u884c\u6548\u7387\u3002<\/strong> <code>matplotlib<\/code>\u5e93\u662fPython\u4e2d\u7528\u4e8e\u7ed8\u5236\u56fe\u5f62\u7684\u6807\u51c6\u5de5\u5177\uff0c\u901a\u8fc7\u8c03\u7528<code>pyplot<\/code>\u6a21\u5757\u4e2d\u7684<code>close<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u548c\u91ca\u653e\u56fe\u5f62\u7a97\u53e3\u6240\u5360\u7528\u7684\u8d44\u6e90\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001MATPLOTLIB\u5e93\u6982\u8ff0<\/h3>\n<\/p>\n<p><p><code>matplotlib<\/code>\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u6765\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u5f62\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u4e8c\u7ef4\u56fe\u5f62\uff0c\u8fd8\u662f\u590d\u6742\u7684\u4e09\u7ef4\u56fe\u5f62\uff0c<code>matplotlib<\/code>\u90fd\u80fd\u80dc\u4efb\u3002<code>pyplot<\/code>\u662f<code>matplotlib<\/code>\u7684\u4e00\u4e2a\u5b50\u6a21\u5757\uff0c\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7528\u4e8e\u7ed8\u56fe\u7684\u51fd\u6570\u63a5\u53e3\uff0c\u7c7b\u4f3c\u4e8eMATLAB\u3002<\/p>\n<\/p>\n<p><h4>1\u3001MATPLOTLIB\u7684\u7ed3\u6784<\/h4>\n<\/p>\n<p><p><code>matplotlib<\/code>\u7684\u6838\u5fc3\u662f\u5176\u5bf9\u8c61\u5c42\u6b21\u7ed3\u6784\u3002\u6700\u9876\u5c42\u7684\u5bf9\u8c61\u662f<code>Figure<\/code>\uff0c\u5b83\u4ee3\u8868\u4e00\u4e2a\u7ed8\u56fe\u7a97\u53e3\u6216\u56fe\u5f62\u7684\u6574\u4f53\u3002\u6bcf\u4e2a<code>Figure<\/code>\u53ef\u4ee5\u5305\u542b\u591a\u4e2a<code>Axes<\/code>\u5bf9\u8c61\uff0c\u6bcf\u4e2a<code>Axes<\/code>\u5bf9\u8c61\u4ee3\u8868\u4e00\u4e2a\u5b50\u56fe\u6216\u7ed8\u56fe\u533a\u57df\u3002\u901a\u8fc7\u8fd9\u79cd\u7ed3\u6784\uff0c<code>matplotlib<\/code>\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u7a97\u53e3\u4e2d\u7ed8\u5236\u591a\u4e2a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h4>2\u3001PYTHON\u4e2dFIGURE\u7684\u521b\u5efa<\/h4>\n<\/p>\n<p><p>\u5728<code>matplotlib<\/code>\u4e2d\uff0c<code>Figure<\/code>\u662f\u901a\u8fc7<code>pyplot<\/code>\u6a21\u5757\u4e2d\u7684<code>figure<\/code>\u51fd\u6570\u521b\u5efa\u7684\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>fig1 = plt.figure()<\/p>\n<p>fig2 = plt.figure()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u521b\u5efa\u4e86\u4e24\u4e2a\u72ec\u7acb\u7684\u56fe\u5f62\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5173\u95edFIGURE\u7684\u5fc5\u8981\u6027<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u6216\u521b\u5efa\u591a\u4e2a\u56fe\u5f62\u65f6\uff0c\u672a\u5173\u95ed\u7684<code>Figure<\/code>\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u6216\u7a0b\u5e8f\u5d29\u6e83\u3002\u56e0\u6b64\uff0c\u53ca\u65f6\u5173\u95ed\u4e0d\u518d\u9700\u8981\u7684\u56fe\u5f62\u7a97\u53e3\u662f\u4e00\u4e2a\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5185\u5b58\u7ba1\u7406<\/h4>\n<\/p>\n<p><p>\u6bcf\u4e2a<code>Figure<\/code>\u5bf9\u8c61\u90fd\u5360\u7528\u4e00\u5b9a\u7684\u5185\u5b58\uff0c\u7279\u522b\u662f\u5728\u7ed8\u5236\u590d\u6742\u56fe\u5f62\u6216\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c\u5185\u5b58\u5360\u7528\u53ef\u80fd\u4f1a\u663e\u8457\u589e\u52a0\u3002\u901a\u8fc7\u5173\u95ed\u4e0d\u5fc5\u8981\u7684<code>Figure<\/code>\uff0c\u53ef\u4ee5\u91ca\u653e\u8fd9\u4e9b\u5185\u5b58\u8d44\u6e90\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u63d0\u9ad8\u7a0b\u5e8f\u6548\u7387<\/h4>\n<\/p>\n<p><p>\u5f53\u7a0b\u5e8f\u521b\u5efa\u591a\u4e2a\u56fe\u5f62\u65f6\uff0c\u672a\u5173\u95ed\u7684\u56fe\u5f62\u53ef\u80fd\u4f1a\u964d\u4f4e\u7a0b\u5e8f\u7684\u8fd0\u884c\u6548\u7387\u3002\u7279\u522b\u662f\u5728\u5faa\u73af\u6216\u6279\u5904\u7406\u64cd\u4f5c\u4e2d\uff0c\u672a\u5173\u95ed\u7684\u56fe\u5f62\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u901f\u5ea6\u53d8\u6162\u3002\u901a\u8fc7\u53ca\u65f6\u5173\u95ed<code>Figure<\/code>\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6574\u4f53\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5982\u4f55\u5173\u95edFIGURE<\/h3>\n<\/p>\n<p><p><code>matplotlib<\/code>\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5173\u95ed<code>Figure<\/code>\u5bf9\u8c61\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>pyplot.close<\/code>\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5173\u95ed\u5355\u4e2aFIGURE<\/h4>\n<\/p>\n<p><p>\u8981\u5173\u95ed\u7279\u5b9a\u7684<code>Figure<\/code>\uff0c\u53ef\u4ee5\u5c06<code>Figure<\/code>\u5bf9\u8c61\u6216\u5176\u7f16\u53f7\u4f20\u9012\u7ed9<code>close<\/code>\u51fd\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5173\u95ed\u7279\u5b9a\u7684Figure<\/p>\n<p>plt.close(fig1)<\/p>\n<h2><strong>\u6216\u8005\u901a\u8fc7\u7f16\u53f7\u5173\u95ed<\/strong><\/h2>\n<p>plt.close(1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5173\u95ed\u6240\u6709FIGURE<\/h4>\n<\/p>\n<p><p>\u8981\u4e00\u6b21\u6027\u5173\u95ed\u6240\u6709\u6253\u5f00\u7684<code>Figure<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528<code>&#39;all&#39;<\/code>\u5173\u952e\u5b57\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">plt.close(&#39;all&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u547d\u4ee4\u4f1a\u904d\u5386\u6240\u6709\u6253\u5f00\u7684<code>Figure<\/code>\u5bf9\u8c61\u5e76\u5c06\u5176\u5173\u95ed\u3002\u8fd9\u5bf9\u4e8e\u5728\u6279\u5904\u7406\u64cd\u4f5c\u6216\u6e05\u7406\u9636\u6bb5\u7279\u522b\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5b9e\u8df5\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5173\u95ed<code>Figure<\/code>\u901a\u5e38\u4e0e\u56fe\u5f62\u7684\u521b\u5efa\u548c\u663e\u793a\u7d27\u5bc6\u7ed3\u5408\u3002\u5728\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u591a\u6b21\u521b\u5efa\u548c\u66f4\u65b0\u56fe\u5f62\uff0c\u56e0\u6b64\u638c\u63e1\u5982\u4f55\u6709\u6548\u5730\u7ba1\u7406<code>Figure<\/code>\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u3001\u663e\u793a\u548c\u5173\u95edFIGURE<\/h4>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u521b\u5efa\u3001\u663e\u793a\u548c\u5173\u95ed\u56fe\u5f62\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u5e76\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>for i in range(3):<\/p>\n<p>    plt.figure()<\/p>\n<p>    plt.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>    plt.title(f&#39;Figure {i+1}&#39;)<\/p>\n<p>    plt.show()<\/p>\n<h2><strong>\u5173\u95ed\u6240\u6709\u56fe\u5f62<\/strong><\/h2>\n<p>plt.close(&#39;all&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e09\u4e2a\u56fe\u5f62\uff0c\u5e76\u5728\u6700\u540e\u5173\u95ed\u4e86\u6240\u6709\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5728\u6570\u636e\u5904\u7406\u6d41\u7a0b\u4e2d\u7684\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5904\u7406\u6d41\u7a0b\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u591a\u6b21\u66f4\u65b0\u56fe\u5f62\u4ee5\u5c55\u793a\u6570\u636e\u7684\u4e0d\u540c\u65b9\u9762\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b9e\u9645\u5e94\u7528\u7684\u793a\u4f8b\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>\u6a21\u62df\u6570\u636e\u5904\u7406\u6d41\u7a0b<\/strong><\/h2>\n<p>for step in range(5):<\/p>\n<p>    data = np.random.randn(100)<\/p>\n<p>    plt.figure()<\/p>\n<p>    plt.hist(data, bins=20, alpha=0.7, label=f&#39;Step {step+1}&#39;)<\/p>\n<p>    plt.legend(loc=&#39;upper right&#39;)<\/p>\n<p>    plt.title(&#39;Data Distribution&#39;)<\/p>\n<p>    plt.show()<\/p>\n<p>    plt.close(&#39;all&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u6a21\u62df\u4e86\u4e00\u4e2a\u6570\u636e\u5904\u7406\u6d41\u7a0b\uff0c\u6bcf\u4e00\u6b65\u90fd\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5206\u5e03\u56fe\u3002\u5728\u663e\u793a\u5b8c\u56fe\u5f62\u540e\uff0c\u6211\u4eec\u7acb\u5373\u5173\u95ed\u4e86\u6240\u6709\u56fe\u5f62\uff0c\u4ee5\u91ca\u653e\u5185\u5b58\u8d44\u6e90\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528<code>matplotlib<\/code>\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u65f6\uff0c\u9075\u5faa\u4ee5\u4e0b\u6700\u4f73\u5b9e\u8df5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u6709\u6548\u5730\u7ba1\u7406\u56fe\u5f62\u8d44\u6e90\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u53ca\u65f6\u5173\u95ed\u4e0d\u5fc5\u8981\u7684FIGURE<\/h4>\n<\/p>\n<p><p>\u5728\u4e0d\u518d\u9700\u8981\u67d0\u4e2a\u56fe\u5f62\u65f6\uff0c\u53ca\u65f6\u5173\u95ed\u5b83\u4ee5\u91ca\u653e\u5185\u5b58\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>plt.close()<\/code>\u51fd\u6570\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u53ef\u4ee5\u5e2e\u52a9\u7ba1\u7406\u8d44\u6e90\u7684\u521b\u5efa\u548c\u91ca\u653e\u3002\u867d\u7136<code>matplotlib<\/code>\u6ca1\u6709\u5185\u7f6e\u7684\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\uff0c\u4f46\u4f60\u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u6765\u7ba1\u7406<code>Figure<\/code>\u5bf9\u8c61\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from contextlib import contextmanager<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>@contextmanager<\/p>\n<p>def managed_figure():<\/p>\n<p>    fig = plt.figure()<\/p>\n<p>    try:<\/p>\n<p>        yield fig<\/p>\n<p>    finally:<\/p>\n<p>        plt.close(fig)<\/p>\n<h2><strong>\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668<\/strong><\/h2>\n<p>with managed_figure():<\/p>\n<p>    plt.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>    plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5728\u8c03\u8bd5\u6a21\u5f0f\u4e2d\u4f7f\u7528<code>plt.ioff()<\/code><\/h4>\n<\/p>\n<p><p>\u5728\u8c03\u8bd5\u6a21\u5f0f\u4e2d\uff0c<code>matplotlib<\/code>\u7684\u4ea4\u4e92\u5f0f\u6a21\u5f0f\u53ef\u80fd\u4f1a\u5bfc\u81f4\u56fe\u5f62\u7a97\u53e3\u81ea\u52a8\u5f39\u51fa\u3002\u901a\u8fc7\u8c03\u7528<code>plt.ioff()<\/code>\u53ef\u4ee5\u5173\u95ed\u4ea4\u4e92\u5f0f\u6a21\u5f0f\uff0c\u4ece\u800c\u9632\u6b62\u4e0d\u5fc5\u8981\u7684\u56fe\u5f62\u7a97\u53e3\u663e\u793a\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u6709\u6548\u7ba1\u7406<code>matplotlib<\/code>\u4e2d\u7684<code>Figure<\/code>\u5bf9\u8c61\u5bf9\u4e8e\u4fdd\u6301\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u81f3\u5173\u91cd\u8981\u3002\u901a\u8fc7\u4f7f\u7528<code>plt.close(&#39;all&#39;)<\/code>\u547d\u4ee4\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5173\u95ed\u6240\u6709\u56fe\u5f62\u7a97\u53e3\uff0c\u91ca\u653e\u5185\u5b58\u8d44\u6e90\u5e76\u63d0\u9ad8\u7a0b\u5e8f\u6548\u7387\u3002\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u6280\u672f\uff0c\u4e0d\u4ec5\u80fd\u5e2e\u52a9\u4f60\u5728\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u8fc7\u7a0b\u4e2d\u66f4\u9ad8\u6548\u5730\u5de5\u4f5c\uff0c\u8fd8\u80fd\u786e\u4fdd\u4f60\u7684\u4ee3\u7801\u5728\u4e0d\u540c\u73af\u5883\u4e0b\u8fd0\u884c\u65f6\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u6709\u6548\u7ba1\u7406\u591a\u4e2a\u56fe\u5f62\u7a97\u53e3\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Python\u7684Matplotlib\u5e93\u65f6\uff0c\u7ba1\u7406\u591a\u4e2a\u56fe\u5f62\u7a97\u53e3\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u9700\u6c42\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528<code>plt.close(&#39;all&#39;)<\/code>\u547d\u4ee4\u5173\u95ed\u6240\u6709\u6253\u5f00\u7684\u56fe\u5f62\u7a97\u53e3\u3002\u8fd9\u6761\u547d\u4ee4\u975e\u5e38\u6709\u6548\uff0c\u5e76\u4e14\u53ef\u4ee5\u786e\u4fdd\u5728\u7ed8\u5236\u65b0\u56fe\u5f62\u4e4b\u524d\uff0c\u6240\u6709\u65e7\u56fe\u5f62\u90fd\u88ab\u6e05\u9664\uff0c\u907f\u514d\u4e86\u5185\u5b58\u5360\u7528\u8fc7\u5927\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u5173\u95ed\u7279\u5b9a\u56fe\u5f62\u7a97\u53e3\u7684\u65b9\u5f0f\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5982\u679c\u60a8\u53ea\u60f3\u5173\u95ed\u7279\u5b9a\u7684\u56fe\u5f62\u7a97\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528<code>plt.close(fig)<\/code>\uff0c\u5176\u4e2d<code>fig<\/code>\u662f\u60a8\u60f3\u8981\u5173\u95ed\u7684\u56fe\u5f62\u5bf9\u8c61\u3002\u8fd9\u79cd\u65b9\u6cd5\u5141\u8bb8\u60a8\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u54ea\u4e9b\u7a97\u53e3\u88ab\u5173\u95ed\uff0c\u800c\u4e0d\u5f71\u54cd\u5176\u4ed6\u6b63\u5728\u67e5\u770b\u7684\u56fe\u5f62\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Jupyter Notebook\u4e2d\u5904\u7406\u56fe\u5f62\u7a97\u53e3\u7684\u5173\u95ed\uff1f<\/strong><br \/>\u5728Jupyter Notebook\u4e2d\uff0c\u4f7f\u7528<code>plt.close()<\/code>\u4e0e<code>plt.show()<\/code>\u7684\u7ec4\u5408\u53ef\u4ee5\u907f\u514d\u56fe\u5f62\u7a97\u53e3\u7684\u91cd\u53e0\u548c\u5806\u53e0\u3002\u8c03\u7528<code>plt.close()<\/code>\u540e\uff0c\u786e\u4fdd\u5728\u6bcf\u6b21\u7ed8\u56fe\u4e4b\u524d\u8c03\u7528\uff0c\u4ee5\u4fdd\u6301\u754c\u9762\u6574\u6d01\u3002\u5982\u679c\u60a8\u5e0c\u671b\u53ea\u663e\u793a\u6700\u65b0\u7684\u56fe\u5f62\u800c\u4e0d\u5173\u95ed\u5176\u4ed6\u7a97\u53e3\uff0c\u53ef\u4ee5\u9009\u62e9\u53ea\u5728\u9700\u8981\u65f6\u4f7f\u7528\u6b64\u547d\u4ee4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528matplotlib.pyplot.close(&#39;all&#39;)\u5173\u95ed\u6240\u6709 [&hellip;]","protected":false},"author":3,"featured_media":977469,"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\/977459"}],"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=977459"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/977459\/revisions"}],"predecessor-version":[{"id":977470,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/977459\/revisions\/977470"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/977469"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=977459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=977459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=977459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}