简体   繁体   English

python matplotlib 如何绘制 20 或所需数量的唯一和不同颜色而不是渐变颜色

[英]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.我想绘制 15 种可能的独特颜色。 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.这部分[::10]是跳过相似的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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