{"id":1109683,"date":"2025-01-08T17:12:23","date_gmt":"2025-01-08T09:12:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1109683.html"},"modified":"2025-01-08T17:12:26","modified_gmt":"2025-01-08T09:12:26","slug":"python-plt%e5%a6%82%e4%bd%95%e6%94%b9%e5%8f%98%e7%94%bb%e5%b8%83%e7%9a%84%e8%83%8c%e6%99%af%e8%89%b2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1109683.html","title":{"rendered":"python plt\u5982\u4f55\u6539\u53d8\u753b\u5e03\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\/25072838\/fe9ee03f-6142-4254-ba58-4e736260a921.webp\" alt=\"python plt\u5982\u4f55\u6539\u53d8\u753b\u5e03\u7684\u80cc\u666f\u8272\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u4f7f\u7528Matplotlib\u5e93\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u6539\u53d8\u753b\u5e03\u7684\u80cc\u666f\u8272\u3002<strong>\u4f7f\u7528<code>plt.figure<\/code>\u7684<code>facecolor<\/code>\u53c2\u6570\u3001<code>set_facecolor<\/code>\u65b9\u6cd5\u3001\u4fee\u6539<code>rcParams<\/code>\u3001<code>patch<\/code>\u5c5e\u6027<\/strong>\u7b49\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u8981\u6539\u53d8\u753b\u5e03\u7684\u80cc\u666f\u8272\uff0c\u53ef\u4ee5\u5728\u521b\u5efa\u56fe\u5f62\u5bf9\u8c61\u65f6\uff0c\u901a\u8fc7<code>plt.figure()<\/code>\u51fd\u6570\u7684<code>facecolor<\/code>\u53c2\u6570\u6307\u5b9a\u80cc\u666f\u989c\u8272\u3002\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\u5e26\u6709\u80cc\u666f\u8272\u7684\u56fe\u5f62<\/strong><\/h2>\n<p>fig = plt.figure(facecolor=&#39;lightblue&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u5b50\u56fe<\/strong><\/h2>\n<p>ax = fig.add_subplot(111)<\/p>\n<h2><strong>\u7ed8\u5236\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\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5728\u521b\u5efa<code>figure<\/code>\u5bf9\u8c61\u65f6\uff0c\u901a\u8fc7\u8bbe\u7f6e<code>facecolor<\/code>\u53c2\u6570\u5c06\u80cc\u666f\u8272\u8bbe\u4e3a<code>lightblue<\/code>\u3002\u4e0b\u9762\u8be6\u7ec6\u8bb2\u89e3\u5176\u4ed6\u65b9\u6cd5\u53ca\u5176\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u6539\u53d8\u6574\u4e2a\u753b\u5e03\u7684\u80cc\u666f\u8272<\/h3>\n<\/p>\n<p><h4>1. \u4f7f\u7528plt.figure()\u7684facecolor\u53c2\u6570<\/h4>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u6700\u4e3a\u76f4\u63a5\u3002\u901a\u8fc7\u5728\u521b\u5efafigure\u5bf9\u8c61\u65f6\u8bbe\u7f6e<code>facecolor<\/code>\u53c2\u6570\uff0c\u53ef\u4ee5\u8f7b\u677e\u6539\u53d8\u753b\u5e03\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5e26\u6709\u80cc\u666f\u8272\u7684\u56fe\u5f62<\/strong><\/h2>\n<p>fig = plt.figure(facecolor=&#39;lightgrey&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u5b50\u56fe<\/strong><\/h2>\n<p>ax = fig.add_subplot(111)<\/p>\n<h2><strong>\u7ed8\u5236\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\u4f8b\u5b50\u4e2d\uff0c\u80cc\u666f\u8272\u88ab\u8bbe\u7f6e\u4e3a<code>lightgrey<\/code>\u3002\u8fd9\u662f\u4e00\u79cd\u975e\u5e38\u7b80\u4fbf\u7684\u65b9\u5f0f\u6765\u8bbe\u5b9a\u753b\u5e03\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528set_facecolor()\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>\u5728\u5df2\u7ecf\u521b\u5efa\u7684\u56fe\u5f62\u5bf9\u8c61\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528<code>set_facecolor()<\/code>\u65b9\u6cd5\u6765\u8bbe\u7f6e\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u8bbe\u7f6e\u56fe\u5f62\u5bf9\u8c61\u7684\u80cc\u666f\u8272<\/strong><\/h2>\n<p>fig.patch.set_facecolor(&#39;lightgreen&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\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\u4f8b\u5b50\u4e2d\uff0c\u9996\u5148\u521b\u5efa\u4e86\u56fe\u5f62\u5bf9\u8c61\uff0c\u7136\u540e\u901a\u8fc7<code>fig.patch.set_facecolor(&#39;lightgreen&#39;)<\/code>\u6765\u8bbe\u5b9a\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h4>3. \u4fee\u6539rcParams<\/h4>\n<\/p>\n<p><p>Matplotlib\u7684<code>rcParams<\/code>\u5141\u8bb8\u6211\u4eec\u5bf9\u9ed8\u8ba4\u8bbe\u7f6e\u8fdb\u884c\u5168\u5c40\u4fee\u6539\uff0c\u4ece\u800c\u5f71\u54cd\u6240\u6709\u56fe\u5f62\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u4fee\u6539\u9ed8\u8ba4\u8bbe\u7f6e<\/strong><\/h2>\n<p>plt.rcParams[&#39;figure.facecolor&#39;] = &#39;lightyellow&#39;<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u7ed8\u5236\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>\u901a\u8fc7\u4fee\u6539<code>rcParams<\/code>\uff0c\u53ef\u4ee5\u5168\u5c40\u8bbe\u7f6e\u753b\u5e03\u7684\u80cc\u666f\u8272\uff0c\u4f7f\u5f97\u540e\u7eed\u521b\u5efa\u7684\u56fe\u5f62\u5bf9\u8c61\u90fd\u91c7\u7528\u76f8\u540c\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u6539\u53d8\u5b50\u56fe\u7684\u80cc\u666f\u8272<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u6211\u4eec\u4e0d\u4ec5\u9700\u8981\u6539\u53d8\u6574\u4e2a\u753b\u5e03\u7684\u80cc\u666f\u8272\uff0c\u8fd8\u9700\u8981\u5bf9\u67d0\u4e9b\u7279\u5b9a\u7684\u5b50\u56fe\u8fdb\u884c\u80cc\u666f\u8272\u8bbe\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528ax.patch.set_facecolor()\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u5bf9\u5b50\u56fe\u5bf9\u8c61\u4f7f\u7528<code>ax.patch.set_facecolor()<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5355\u72ec\u8bbe\u7f6e\u5b50\u56fe\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u8bbe\u7f6e\u5b50\u56fe\u7684\u80cc\u666f\u8272<\/strong><\/h2>\n<p>ax.patch.set_facecolor(&#39;lightcoral&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\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\u4f8b\u5b50\u4e2d\uff0c\u5b50\u56fe\u7684\u80cc\u666f\u8272\u88ab\u8bbe\u7f6e\u4e3a<code>lightcoral<\/code>\uff0c\u800c\u6574\u4e2a\u753b\u5e03\u7684\u80cc\u666f\u8272\u4fdd\u6301\u9ed8\u8ba4\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u80cc\u666f\u8272\u5c5e\u6027<\/h4>\n<\/p>\n<p><p>\u5728Matplotlib\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u5c5e\u6027\u76f4\u63a5\u8bbe\u7f6e\u5b50\u56fe\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u8bbe\u7f6e\u5b50\u56fe\u7684\u80cc\u666f\u8272<\/strong><\/h2>\n<p>ax.set_facecolor(&#39;lavender&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\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>\u8fd9\u91cc\u4f7f\u7528\u4e86<code>ax.set_facecolor(&#39;lavender&#39;)<\/code>\u6765\u6539\u53d8\u5b50\u56fe\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u6539\u53d8\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u6539\u53d8\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272\uff0c\u800c\u4e0d\u662f\u6574\u4e2a\u5b50\u56fe\u7684\u80cc\u666f\u8272\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528ax.set_axis_bgcolor()\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>\u8fd9\u4e2a\u65b9\u6cd5\u5728\u8001\u7248\u672c\u7684Matplotlib\u4e2d\u4f7f\u7528\u8f83\u591a\uff0c\u4f46\u5728\u65b0\u7248\u672c\u4e2d\u5df2\u88ab\u5f03\u7528\uff0c\u6539\u7528<code>ax.set_facecolor()<\/code>\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62\u5bf9\u8c61<\/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;whitesmoke&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\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\u4f8b\u5b50\u4e2d\uff0c\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272\u88ab\u8bbe\u7f6e\u4e3a<code>whitesmoke<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\u8fdb\u884c\u80cc\u666f\u8272\u8bbe\u7f6e<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u590d\u6742\u7684\u80cc\u666f\u8272\u8bbe\u7f6e\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u4fee\u6539\u9ed8\u8ba4\u8bbe\u7f6e<\/strong><\/h2>\n<p>plt.rcParams[&#39;figure.facecolor&#39;] = &#39;lightblue&#39;<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u8bbe\u7f6e\u5b50\u56fe\u7684\u80cc\u666f\u8272<\/strong><\/h2>\n<p>ax.set_facecolor(&#39;lightgrey&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\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\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u901a\u8fc7<code>rcParams<\/code>\u8bbe\u7f6e\u4e86\u5168\u5c40\u7684\u753b\u5e03\u80cc\u666f\u8272\uff0c\u7136\u540e\u4f7f\u7528<code>ax.set_facecolor()<\/code>\u65b9\u6cd5\u5355\u72ec\u8bbe\u7f6e\u5b50\u56fe\u7684\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u7b80\u5316\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u7b80\u5316\u64cd\u4f5c\uff0c\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u6765\u8bbe\u7f6e\u80cc\u666f\u8272\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>def set_background_color(fig, ax, fig_color=&#39;white&#39;, ax_color=&#39;white&#39;):<\/p>\n<p>    fig.patch.set_facecolor(fig_color)<\/p>\n<p>    ax.set_facecolor(ax_color)<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u8bbe\u7f6e\u80cc\u666f\u8272<\/strong><\/h2>\n<p>set_background_color(fig, ax, fig_color=&#39;lightpink&#39;, ax_color=&#39;lightcyan&#39;)<\/p>\n<h2><strong>\u7ed8\u5236\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>\u901a\u8fc7\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u53ef\u4ee5\u66f4\u52a0\u65b9\u4fbf\u5730\u5bf9\u56fe\u5f62\u5bf9\u8c61\u8fdb\u884c\u80cc\u666f\u8272\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u7684Matplotlib\u5e93\u4e2d\uff0c<strong>\u6539\u53d8\u753b\u5e03\u7684\u80cc\u666f\u8272<\/strong>\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec<code>plt.figure<\/code>\u7684<code>facecolor<\/code>\u53c2\u6570\u3001<code>set_facecolor<\/code>\u65b9\u6cd5\u3001\u4fee\u6539<code>rcParams<\/code>\u3001<code>patch<\/code>\u5c5e\u6027\u7b49\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u573a\u666f\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u8fdb\u884c\u80cc\u666f\u8272\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u662f\u6539\u53d8\u6574\u4e2a\u753b\u5e03\u3001\u7279\u5b9a\u5b50\u56fe\uff0c\u8fd8\u662f\u7ed8\u56fe\u533a\u57df\u7684\u80cc\u666f\u8272\uff0cMatplotlib\u90fd\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u63a5\u53e3\uff0c\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u5404\u79cd\u4e2a\u6027\u5316\u8bbe\u7f6e\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\uff0c\u751a\u81f3\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u6765\u63d0\u9ad8\u64cd\u4f5c\u7684\u4fbf\u6377\u6027\u548c\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u7684Matplotlib\u4e2d\u8bbe\u7f6e\u753b\u5e03\u7684\u80cc\u666f\u8272\uff1f<\/strong><br \/>\u5728Matplotlib\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>figure<\/code>\u5bf9\u8c61\u7684<code>facecolor<\/code>\u53c2\u6570\u6765\u6539\u53d8\u753b\u5e03\u7684\u80cc\u666f\u8272\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>plt.figure(facecolor=&#39;lightblue&#39;)<\/code>\u53ef\u4ee5\u5c06\u80cc\u666f\u8272\u8bbe\u7f6e\u4e3a\u6d45\u84dd\u8272\u3002\u8fd8\u53ef\u4ee5\u5728\u521b\u5efa\u56fe\u5f62\u65f6\u6307\u5b9a\u989c\u8272\uff0c\u6216\u8005\u4f7f\u7528<code>set_facecolor()<\/code>\u65b9\u6cd5\u6765\u66f4\u6539\u73b0\u6709\u56fe\u5f62\u7684\u80cc\u666f\u8272\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4e3aMatplotlib\u4e2d\u7684\u6bcf\u4e2a\u5b50\u56fe\u5355\u72ec\u8bbe\u7f6e\u80cc\u666f\u8272\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u5b50\u56fe\u5355\u72ec\u8bbe\u7f6e\u80cc\u666f\u8272\u3002\u5728\u521b\u5efa\u5b50\u56fe\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>set_facecolor()<\/code>\u65b9\u6cd5\u6765\u6307\u5b9a\u6bcf\u4e2a\u5b50\u56fe\u7684\u80cc\u666f\u989c\u8272\uff0c\u4f8b\u5982<code>ax.set_facecolor(&#39;lightgreen&#39;)<\/code>\u3002\u8fd9\u6837\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u5b9a\u4e49\u6bcf\u4e2a\u5b50\u56fe\u7684\u5916\u89c2\u3002<\/p>\n<p><strong>\u5728\u6539\u53d8\u80cc\u666f\u8272\u65f6\uff0c\u5982\u4f55\u786e\u4fdd\u6570\u636e\u53ef\u89c6\u5316\u7684\u6e05\u6670\u5ea6\uff1f<\/strong><br \/>\u9009\u62e9\u80cc\u666f\u8272\u65f6\uff0c\u786e\u4fdd\u4e0e\u6570\u636e\u548c\u56fe\u5f62\u5143\u7d20\u5f62\u6210\u5bf9\u6bd4\u975e\u5e38\u91cd\u8981\u3002\u4f8b\u5982\uff0c\u6d45\u8272\u80cc\u666f\u9002\u5408\u6df1\u8272\u7684\u7ebf\u6761\u548c\u6807\u8bb0\uff0c\u800c\u6df1\u8272\u80cc\u666f\u5219\u9002\u5408\u6d45\u8272\u5143\u7d20\u3002\u4f7f\u7528<code>plt.grid()<\/code>\u53ef\u4ee5\u6dfb\u52a0\u7f51\u683c\u7ebf\uff0c\u589e\u5f3a\u6570\u636e\u7684\u53ef\u8bfb\u6027\u3002\u6b64\u5916\uff0c\u8c03\u6574\u6587\u672c\u548c\u6807\u8bb0\u7684\u989c\u8272\u4e5f\u6709\u52a9\u4e8e\u63d0\u9ad8\u6574\u4f53\u53ef\u89c6\u5316\u6548\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u4f7f\u7528Matplotlib\u5e93\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u6539\u53d8\u753b\u5e03\u7684\u80cc\u666f\u8272\u3002\u4f7f\u7528plt.figure\u7684fa [&hellip;]","protected":false},"author":3,"featured_media":1109693,"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\/1109683"}],"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=1109683"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1109683\/revisions"}],"predecessor-version":[{"id":1109695,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1109683\/revisions\/1109695"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1109693"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1109683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1109683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1109683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}