How can I generate more colors on pie chart matplotlib

前端 未结 3 2108
情歌与酒
情歌与酒 2021-02-13 19:41

I am having more then 40 items to show in my chart. I have only 10 colours that repeatedly are shown on the chart. How can I generate more colors.

plt.pie(f,la         


        
3条回答
  •  灰色年华
    2021-02-13 20:02

    You need colors argument, beside that you can use some color maps from cm.

    import matplotlib.pyplot as plt
    from matplotlib import cm
    import numpy as np
    a=np.random.random(40)
    cs=cm.Set1(np.arange(40)/40.)
    f=plt.figure()
    ax=f.add_subplot(111, aspect='equal')
    p=plt.pie(a, colors=cs)
    plt.show()
    

    enter image description here

    Beside using colormaps, also consider using .set_color_cycle() method. See this post: plotting different colors in matplotlib

提交回复
热议问题