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

2024-05-19 15:53:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将matplotlib的标准颜色旋转更改为另一个colormap。具体来说,我想用“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)

所以我想我只是在找合适的钥匙来添加。在


Tags: import标准matplotlib颜色aspltparamsmpl
1条回答
网友
1楼 · 发布于 2024-05-19 15:53:47

您需要为"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()

{a1}

相关问题 更多 >