CDF, matplotlib - not enough colors for plot, python

后端 未结 3 1105
半阙折子戏
半阙折子戏 2021-01-23 21:11

Here is needed to plot CDF for 8 different functions in one plot. The problem that it gives just 7 different colors and the 8 one gives just first blue color again. How to make

3条回答
  •  北海茫月
    2021-01-23 21:51

    Easiest solution: Give the last curve a different color:

    plt.plot(h_sh[1:], hy_1st,label='Hilbert_SbS', color="orange")
    

    Matplotlib version 1.5 or below has 7 different colors in its color cycle, while matplotlib 2.0 has 10 different colors. Hence, updating matplotlib is another option.

    In general, you may of course define your own color cycle which has as many colors as you wish.

    • Build a cycler from a colormap, as shown in this question:

      import matplotlib.pyplot as plt
      from cycler import cycler
      import numpy as np
      
      N = 8 # number of colors
      plt.rcParams["axes.prop_cycle"] = cycler('color', plt.cm.jet(np.linspace(0,1,N)) )
      
    • Build a cycler from a list of colors:

      import matplotlib.pyplot as plt
      from cycler import cycler
      
      colors=["aquamarine","crimson","gold","indigo",
              "lime","orange","orchid","sienna"]
      plt.rcParams["axes.prop_cycle"] = cycler('color',colors)
      

提交回复
热议问题