擅长:python、mysql、java
<p>若要仅更改当前交互会话或一个脚本的默认颜色映射,请使用</p>
<pre><code>import matplotlib as mpl
mpl.rc('image', cmap='gray')
</code></pre>
<p>对于2.0之前的<code>matplotlib</code>版本,必须使用rcParams dict。这在较新版本中仍然有效。</p>
<pre><code>import matplotlib.pyplot as plt
plt.rcParams['image.cmap'] = 'gray'
</code></pre>
<p>要永久更改默认颜色映射,请编辑matplotlibrc配置文件并添加<code>image.cmap: gray</code>行。
根据需要,将值gray替换为任何其他有效的colormap。
配置文件应该位于<code>~/.config/matplotlib/matplotlibrc</code>,但是您可以使用</p>
<pre><code>mpl.matplotlib_fname()
</code></pre>
<p>如果在不同的虚拟环境中有多个matplotlib版本,则此功能尤其有用。</p>
<p>另见<a href="http://txt.arboreus.com/2014/10/21/how-to-set-default-colormap-in-matplotlib.html" rel="noreferrer">http://txt.arboreus.com/2014/10/21/how-to-set-default-colormap-in-matplotlib.html</a>
以及Matplotlib<a href="http://matplotlib.org/users/customizing.html" rel="noreferrer">http://matplotlib.org/users/customizing.html</a>的一般配置</p>