擅长:python、mysql、java
<p>一种方法是在脚本中手动设置轴背景色的默认值(请参见<a href="http://matplotlib.org/users/customizing.html" rel="noreferrer">Customizing matplotlib</a>):</p>
<pre class="lang-py prettyprint-override"><code>import matplotlib.pyplot as plt
plt.rcParams['axes.facecolor'] = 'black'
</code></pre>
<p>这与Nick T改变特定<code>axes</code>对象背景颜色的方法形成对比。如果要使用相似的样式生成多个不同的绘图,并且不想继续更改不同的<code>axes</code>对象,则重置默认值非常有用。</p>
<p><em>注:相当于</em>
</p>
<pre><code>fig = plt.figure()
fig.patch.set_facecolor('black')
</code></pre>
<p>你的问题是:</em>
</p>
<pre><code>plt.rcParams['figure.facecolor'] = 'black'
</code></pre>