{"id":1098791,"date":"2025-01-08T15:24:25","date_gmt":"2025-01-08T07:24:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1098791.html"},"modified":"2025-01-08T15:24:27","modified_gmt":"2025-01-08T07:24:27","slug":"python%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae%e7%bb%98%e5%9b%be%e7%9a%84%e8%83%8c%e6%99%af%e8%89%b2-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1098791.html","title":{"rendered":"python\u5982\u4f55\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25062823\/60865881-f233-4db0-b01a-462f07a782a8.webp\" alt=\"python\u5982\u4f55\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\uff0c<strong>\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\u3001\u53ef\u4ee5\u8bbe\u7f6e\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272\u3001\u53ef\u4ee5\u8bbe\u7f6e\u6574\u4e2aFigure\u7684\u80cc\u666f\u8272<\/strong>\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u8be6\u7ec6\u7684\u8bb2\u89e3\u548c\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Matplotlib\u5e93\u6765\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272<\/h3>\n<\/p>\n<p><p>Matplotlib\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7Matplotlib\u5e93\u4e2d\u7684\u5404\u79cd\u65b9\u6cd5\u6765\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u8bbe\u7f6e\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7Axes\u5bf9\u8c61\u7684<code>set_facecolor()<\/code>\u65b9\u6cd5\u6765\u8bbe\u7f6e\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aFigure\u548c\u4e00\u4e2aAxes<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u8bbe\u7f6e\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272<\/strong><\/h2>\n<p>ax.set_facecolor(&#39;lightblue&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>ax.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/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\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>ax.set_facecolor(&#39;lightblue&#39;)<\/code>\u6765\u5c06\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272\u8bbe\u7f6e\u4e3a\u6d45\u84dd\u8272\u3002<\/p>\n<\/p>\n<p><h4>1.2 \u8bbe\u7f6e\u6574\u4e2aFigure\u7684\u80cc\u666f\u8272<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7Figure\u5bf9\u8c61\u7684<code>set_facecolor()<\/code>\u65b9\u6cd5\u6765\u8bbe\u7f6e\u6574\u4e2aFigure\u7684\u80cc\u666f\u8272\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aFigure\u548c\u4e00\u4e2aAxes<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u8bbe\u7f6e\u6574\u4e2aFigure\u7684\u80cc\u666f\u8272<\/strong><\/h2>\n<p>fig.patch.set_facecolor(&#39;lightgreen&#39;)<\/p>\n<h2><strong>\u8bbe\u7f6e\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272<\/strong><\/h2>\n<p>ax.set_facecolor(&#39;lightblue&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>ax.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/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\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>fig.patch.set_facecolor(&#39;lightgreen&#39;)<\/code>\u6765\u5c06\u6574\u4e2aFigure\u7684\u80cc\u666f\u8272\u8bbe\u7f6e\u4e3a\u6d45\u7eff\u8272\uff0c\u540c\u65f6\u4f7f\u7528<code>ax.set_facecolor(&#39;lightblue&#39;)<\/code>\u6765\u5c06\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272\u8bbe\u7f6e\u4e3a\u6d45\u84dd\u8272\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u8bbe\u7f6e\u5b50\u56fe\u7684\u80cc\u666f\u8272<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5728\u4e00\u4e2aFigure\u4e2d\u5305\u542b\u591a\u4e2a\u5b50\u56fe\uff0c\u5e76\u4e14\u5e0c\u671b\u6bcf\u4e2a\u5b50\u56fe\u6709\u4e0d\u540c\u7684\u80cc\u666f\u8272\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>subplots()<\/code>\u65b9\u6cd5\u6765\u521b\u5efa\u591a\u4e2a\u5b50\u56fe\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u5b50\u56fe\u5206\u522b\u8bbe\u7f6e\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h4>2.1 \u521b\u5efa\u591a\u4e2a\u5b50\u56fe\u5e76\u8bbe\u7f6e\u80cc\u666f\u8272<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u521b\u5efa\u591a\u4e2a\u5b50\u56fe\u5e76\u4e3a\u6bcf\u4e2a\u5b50\u56fe\u8bbe\u7f6e\u4e0d\u540c\u7684\u80cc\u666f\u8272\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5305\u542b4\u4e2a\u5b50\u56fe\u7684Figure<\/strong><\/h2>\n<p>fig, axs = plt.subplots(2, 2)<\/p>\n<h2><strong>\u8bbe\u7f6e\u6bcf\u4e2a\u5b50\u56fe\u7684\u80cc\u666f\u8272<\/strong><\/h2>\n<p>axs[0, 0].set_facecolor(&#39;lightblue&#39;)<\/p>\n<p>axs[0, 1].set_facecolor(&#39;lightgreen&#39;)<\/p>\n<p>axs[1, 0].set_facecolor(&#39;lightyellow&#39;)<\/p>\n<p>axs[1, 1].set_facecolor(&#39;lightpink&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>for ax in axs.flat:<\/p>\n<p>    ax.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<h2><strong>\u8c03\u6574\u5b50\u56fe\u4e4b\u95f4\u7684\u95f4\u8ddd<\/strong><\/h2>\n<p>plt.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>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>axs[0, 0].set_facecolor(&#39;lightblue&#39;)<\/code>\u7b49\u65b9\u6cd5\u6765\u5206\u522b\u8bbe\u7f6e\u6bcf\u4e2a\u5b50\u56fe\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u8bbe\u7f6e\u7279\u5b9a\u533a\u57df\u7684\u80cc\u666f\u8272<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5728\u540c\u4e00\u4e2a\u7ed8\u56fe\u533a\u57df\u4e2d\u8bbe\u7f6e\u7279\u5b9a\u533a\u57df\u7684\u80cc\u666f\u8272\uff0c\u6bd4\u5982\u7ed8\u56fe\u533a\u57df\u7684\u4e00\u90e8\u5206\u80cc\u666f\u8272\u4e0d\u540c\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u7ed8\u5236\u77e9\u5f62\uff08Rectangle\uff09\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<\/p>\n<p><h4>3.1 \u4f7f\u7528Rectangle\u6765\u8bbe\u7f6e\u7279\u5b9a\u533a\u57df\u7684\u80cc\u666f\u8272<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5728\u7ed8\u56fe\u533a\u57df\u4e2d\u4f7f\u7528Rectangle\u6765\u8bbe\u7f6e\u7279\u5b9a\u533a\u57df\u7684\u80cc\u666f\u8272\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.patches as patches<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aFigure\u548c\u4e00\u4e2aAxes<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u7ed8\u5236\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>ax.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/p>\n<h2><strong>\u6dfb\u52a0\u4e00\u4e2a\u77e9\u5f62\u6765\u8bbe\u7f6e\u7279\u5b9a\u533a\u57df\u7684\u80cc\u666f\u8272<\/strong><\/h2>\n<p>rect = patches.Rectangle((1.5, 15), 1.5, 10, linewidth=0, edgecolor=&#39;none&#39;, facecolor=&#39;lightyellow&#39;, alpha=0.5)<\/p>\n<p>ax.add_patch(rect)<\/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\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>patches.Rectangle<\/code>\u6765\u521b\u5efa\u4e00\u4e2a\u77e9\u5f62\uff0c\u5e76\u4f7f\u7528<code>ax.add_patch(rect)<\/code>\u5c06\u5176\u6dfb\u52a0\u5230\u7ed8\u56fe\u533a\u57df\u4e2d\uff0c\u4ece\u800c\u8bbe\u7f6e\u7279\u5b9a\u533a\u57df\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u901a\u8fc7\u6837\u5f0f\u8868\u548c\u53c2\u6570\u914d\u7f6e<\/h3>\n<\/p>\n<p><p>Matplotlib\u63d0\u4f9b\u4e86\u6837\u5f0f\u8868\uff08style sheet\uff09\u548c\u53c2\u6570\u914d\u7f6e\uff08rcParams\uff09\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\u4ee5\u53ca\u5176\u4ed6\u6837\u5f0f\u5c5e\u6027\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u4f7f\u7528\u6837\u5f0f\u8868\u8bbe\u7f6e\u80cc\u666f\u8272<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u6837\u5f0f\u8868\u6765\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6837\u5f0f\u8868<\/strong><\/h2>\n<p>plt.style.use({<\/p>\n<p>    &#39;figure.facecolor&#39;: &#39;lightgray&#39;,<\/p>\n<p>    &#39;axes.facecolor&#39;: &#39;lightblue&#39;,<\/p>\n<p>})<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aFigure\u548c\u4e00\u4e2aAxes<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u7ed8\u5236\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>ax.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/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\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>plt.style.use()<\/code>\u65b9\u6cd5\u6765\u5e94\u7528\u81ea\u5b9a\u4e49\u7684\u6837\u5f0f\u8868\uff0c\u4ece\u800c\u8bbe\u7f6eFigure\u548cAxes\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h4>4.2 \u4f7f\u7528rcParams\u8bbe\u7f6e\u80cc\u666f\u8272<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7rcParams\u6765\u5168\u5c40\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u8bbe\u7f6ercParams\u6765\u5168\u5c40\u8bbe\u7f6e\u80cc\u666f\u8272<\/strong><\/h2>\n<p>plt.rcParams[&#39;figure.facecolor&#39;] = &#39;lightgray&#39;<\/p>\n<p>plt.rcParams[&#39;axes.facecolor&#39;] = &#39;lightblue&#39;<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aFigure\u548c\u4e00\u4e2aAxes<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u7ed8\u5236\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>ax.plot([1, 2, 3, 4], [10, 20, 25, 30])<\/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\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>plt.rcParams<\/code>\u6765\u5168\u5c40\u8bbe\u7f6eFigure\u548cAxes\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u51e0\u79cd\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5728Python\u4e2d\u4f7f\u7528Matplotlib\u5e93\u6765\u65b9\u4fbf\u5730\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528Axes\u5bf9\u8c61\u7684<code>set_facecolor()<\/code>\u65b9\u6cd5\u6765\u8bbe\u7f6e\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272\u3002<\/li>\n<li>\u4f7f\u7528Figure\u5bf9\u8c61\u7684<code>set_facecolor()<\/code>\u65b9\u6cd5\u6765\u8bbe\u7f6e\u6574\u4e2aFigure\u7684\u80cc\u666f\u8272\u3002<\/li>\n<li>\u4f7f\u7528<code>subplots()<\/code>\u65b9\u6cd5\u521b\u5efa\u591a\u4e2a\u5b50\u56fe\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u5b50\u56fe\u8bbe\u7f6e\u4e0d\u540c\u7684\u80cc\u666f\u8272\u3002<\/li>\n<li>\u4f7f\u7528Rectangle\u6765\u8bbe\u7f6e\u7279\u5b9a\u533a\u57df\u7684\u80cc\u666f\u8272\u3002<\/li>\n<li>\u4f7f\u7528\u6837\u5f0f\u8868\uff08style sheet\uff09\u548c\u53c2\u6570\u914d\u7f6e\uff08rcParams\uff09\u6765\u5168\u5c40\u8bbe\u7f6e\u80cc\u666f\u8272\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u5b9a\u4e49\u7ed8\u56fe\u7684\u5916\u89c2\uff0c\u4f7f\u5176\u66f4\u52a0\u7f8e\u89c2\u548c\u6613\u4e8e\u7406\u89e3\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6839\u636e\u5177\u4f53\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u5e76\u7ed3\u5408\u5176\u4ed6\u56fe\u5f62\u5143\u7d20\u7684\u8bbe\u7f6e\uff0c\u80fd\u591f\u521b\u5efa\u51fa\u66f4\u52a0\u4e13\u4e1a\u548c\u5177\u6709\u89c6\u89c9\u5438\u5f15\u529b\u7684\u56fe\u8868\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u989c\u8272\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528Matplotlib\u5e93\u53ef\u4ee5\u8f7b\u677e\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u989c\u8272\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>plt.figure()<\/code>\u51fd\u6570\u5e76\u4f20\u9012<code>facecolor<\/code>\u53c2\u6570\u6765\u6307\u5b9a\u80cc\u666f\u8272\u3002\u4f8b\u5982\uff0c<code>plt.figure(facecolor=&#39;lightblue&#39;)<\/code>\u5c06\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u4e3a\u6d45\u84dd\u8272\u3002\u6b64\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>ax.set_facecolor(&#39;color&#39;)<\/code>\u65b9\u6cd5\u6765\u6539\u53d8\u7279\u5b9a\u5750\u6807\u8f74\u7684\u80cc\u666f\u8272\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4e3a\u4e0d\u540c\u7684\u56fe\u5f62\u5143\u7d20\u8bbe\u7f6e\u4e0d\u540c\u7684\u80cc\u666f\u989c\u8272\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u4e3a\u4e0d\u540c\u7684\u56fe\u5f62\u5143\u7d20\uff08\u5982\u56fe\u5f62\u533a\u57df\u548c\u5750\u6807\u8f74\uff09\u8bbe\u7f6e\u4e0d\u540c\u7684\u80cc\u666f\u989c\u8272\u3002\u901a\u8fc7\u4f7f\u7528<code>plt.gca().set_facecolor(&#39;color&#39;)<\/code>\u53ef\u4ee5\u6539\u53d8\u5f53\u524d\u5750\u6807\u8f74\u7684\u80cc\u666f\u8272\u3002\u800c\u5982\u679c\u60a8\u60f3\u4e3a\u6574\u4e2a\u56fe\u5f62\u8bbe\u7f6e\u80cc\u666f\uff0c\u53ef\u4ee5\u5728\u521b\u5efa\u56fe\u5f62\u65f6\u4f7f\u7528<code>plt.figure(facecolor=&#39;color&#39;)<\/code>\u3002<\/p>\n<p><strong>\u5728Python\u7ed8\u56fe\u4e2d\uff0c\u80cc\u666f\u989c\u8272\u7684\u9009\u62e9\u4f1a\u5f71\u54cd\u89c6\u89c9\u6548\u679c\u5417\uff1f<\/strong><br \/>\u80cc\u666f\u989c\u8272\u786e\u5b9e\u4f1a\u5f71\u54cd\u56fe\u5f62\u7684\u89c6\u89c9\u6548\u679c\u548c\u53ef\u8bfb\u6027\u3002\u9009\u62e9\u9002\u5408\u7684\u80cc\u666f\u8272\u53ef\u4ee5\u63d0\u5347\u6570\u636e\u7684\u53ef\u89c6\u5316\u6548\u679c\uff0c\u4f7f\u5f97\u56fe\u5f62\u4e2d\u7684\u6570\u636e\u70b9\u3001\u7ebf\u6761\u548c\u6587\u672c\u66f4\u52a0\u7a81\u51fa\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u6d45\u8272\u80cc\u666f\u9002\u5408\u5c55\u793a\u6df1\u8272\u6570\u636e\uff0c\u800c\u6df1\u8272\u80cc\u666f\u5219\u9002\u5408\u5c55\u793a\u6d45\u8272\u6570\u636e\uff0c\u4ee5\u4fdd\u8bc1\u826f\u597d\u7684\u5bf9\u6bd4\u5ea6\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u8bbe\u7f6e\u7ed8\u56fe\u7684\u80cc\u666f\u8272\u3001\u53ef\u4ee5 [&hellip;]","protected":false},"author":3,"featured_media":1098799,"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\/1098791"}],"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=1098791"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1098791\/revisions"}],"predecessor-version":[{"id":1098803,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1098791\/revisions\/1098803"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1098799"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1098791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1098791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1098791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}