Skip to content Skip to sidebar Skip to footer

Change Default Color Rotation Matplotlib To Specific Colormap

I would like to change the standard color rotation of matplotlib to another colormap. To be specific, I would like to use 'gdist_rainbow'. Is that possible and if so, how can i ach

Solution 1:

You need to supply a color cycle to the "axes.prop_cycle" rcParameter. A color cycle consists of a list of colors. Those can be chosen according to a colormap. See example below:

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 inrange(30):
    plt.plot(x,f(x,i/30.*np.pi) )

plt.show()

enter image description here

Post a Comment for "Change Default Color Rotation Matplotlib To Specific Colormap"