change default color rotation matplotlib to specific colormap

后端 未结 1 1257
时光说笑
时光说笑 2020-12-18 11:56

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

相关标签:
1条回答
  • 2020-12-18 12:48

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

    0 讨论(0)
提交回复
热议问题