简体   繁体   中英

python matplotlib how to plot 20 or required number unique and different colors not gradient colors

I want to plot unique colors of required numbers but not gradient colors between two colors.

My code:

import random
from colour import Color

clr_list = list(Color("red").range_to(Color("green"),30)

for i in range(0,15):
    randomlist = []
    for j in range(0,5):
        n = random.randint(1,30)
        randomlist.append(n)
    plt.plot(randomlist,color=clr_list[i].rgb,label=i)
plt.legend(loc='center left',fontsize = 8)
plt.show()

My present output:

在此处输入图片说明

The above plot makes it hard to distinguish different lines. I would like to plot 15 unique colors possible. How to achive this?

You can create a list with a lot of colors and take some of them:

import matplotlib._color_data as mcd
palette = list(mcd.XKCD_COLORS.values())[::10]

This part [::10] is to skip similar colors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM