CDF, matplotlib - not enough colors for plot, python

后端 未结 3 1204
半阙折子戏
半阙折子戏 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:48

    I love to read my colors directly from a colormap with this code

    def getColor(c, N, idx):
        import matplotlib as mpl
        cmap = mpl.cm.get_cmap(c)
        norm = mpl.colors.Normalize(vmin=0.0, vmax=N - 1)
        return cmap(norm(idx))
    

    Here, c is the name of the colormap (see https://matplotlib.org/examples/color/colormaps_reference.html for a list), N is the number of colors you want in total, and idx is just an index that will yield the specific color.

    Then when calling the plot function, just add the color=getColor(c, N, idx) option.

提交回复
热议问题