小编典典

将默认颜色旋转matplotlib更改为特定的颜色图

python

我想将matplotlib的标准颜色旋转更改为另一个颜色图。具体来说,我想使用“ gdist_rainbow”。那有可能吗,如果可以的话,我该如何实现呢?

我已经有自定义设置,例如

import matplotlib as mpl
import matplotlib.pyplot as plt
params = {'legend.fontsize': 'x-large',
         'axes.labelsize': 'xx-large',
         'axes.titlesize':'xx-large',
         'xtick.labelsize':'xx-large',
         'ytick.labelsize':'xx-large',
         'lines.markersize':8,
         'figure.autolayout':True}
plt.rcParams.update(params)

所以我想我只是在寻找要添加的正确键。


阅读 526

收藏
2021-01-20

共1个答案

小编典典

您需要为"axes.prop_cycle"rcParameter提供一个颜色循环。一个颜色循环由颜色列表组成。可以根据颜色图进行选择。请参见下面的示例:

import matplotlib.pyplot as plt
from cycler import cycler
import numpy as np

# get colormap
cmap=plt.cm.gist_rainbow
# build cycler with 5 equally spaced colors from that colormap
c = cycler('color', cmap(np.linspace(0,1,5)) )
# supply cycler to the rcParam
plt.rcParams["axes.prop_cycle"] = c


x = np.linspace(0,2*np.pi)
f = lambda x, phase:np.sin(x+phase)
for i in range(30):
    plt.plot(x,f(x,i/30.*np.pi) )

plt.show()

在此处输入图片说明

2021-01-20