如何使用matplotlib设置所有子图的默认颜色周期? [英] How to set the default color cycle for all subplots with matplotlib?
本文介绍了如何使用matplotlib设置所有子图的默认颜色周期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为使用matplotlib制作的绘图设置默认颜色集?我可以像这样设置一个特定的颜色映射
How can I set a default set of colors for plots made with matplotlib? I can set a particular color map like this
import numpy as np
import matplotlib.pyplot as plt
fig=plt.figure(i)
ax=plt.gca()
colormap = plt.get_cmap('jet')
ax.set_color_cycle([colormap(k) for k in np.linspace(0, 1, 10)])
为所有地块设置相同的颜色集,包括子图?
but is there some way to set the same set of colors for all plots, including subplots?
推荐答案
可以在中指定
文件或在运行时使用 axes.color_cycle
c $ c> .matplotlibrc matplotlib.rcParams
或或matplotlib.rc
Sure! Either specify axes.color_cycle
in your .matplotlibrc
file or set it at runtime using matplotlib.rcParams
or matplotlib.rc
.
作为后者的示例:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
# Set the default color cycle
mpl.rcParams['axes.color_cycle'] = ['r', 'k', 'c']
# Alternately, we could use rc:
# mpl.rc('axes', color_cycle=['r','k','c'])
x = np.linspace(0, 20, 100)
fig, axes = plt.subplots(nrows=2)
for i in range(10):
axes[0].plot(x, i * (x - 10)**2)
for i in range(10):
axes[1].plot(x, i * np.cos(x))
plt.show()
这篇关于如何使用matplotlib设置所有子图的默认颜色周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文