简体   繁体   中英

Is there a pre-defined color list? so I could access the colors by index

I was wondering if there is a pre-defined color list.
For example colors = ['red', 'orange', 'yellow'...]

I wanted assign items with colors, However the number of items is not set and is unknown.
So I was trying to set a code such as

color_dict = {}
for num, i in enumerate(list_with_random_items):
    color_dict[i] = colors[num]

Is creating my own list of colors (ex. colors=['red', 'yellow'] ) the only way?

I used matplotlib.colors

import matplotlib.colors as mcl

mcl.BASE_COLORS

mlc.TABLEAU_COLORS

gives output of

{'b': (0, 0, 1),
 'g': (0, 0.5, 0),
 'r': (1, 0, 0),
 'c': (0, 0.75, 0.75),
 'm': (0.75, 0, 0.75),
 'y': (0.75, 0.75, 0),
 'k': (0, 0, 0),
 'w': (1, 1, 1)}

==========================

OrderedDict([('tab:blue', '#1f77b4'),
             ('tab:orange', '#ff7f0e'),
             ('tab:green', '#2ca02c'),
             ('tab:red', '#d62728'),
             ('tab:purple', '#9467bd'),
             ('tab:brown', '#8c564b'),
             ('tab:pink', '#e377c2'),
             ('tab:gray', '#7f7f7f'),
             ('tab:olive', '#bcbd22'),
             ('tab:cyan', '#17becf')])

and just used the keys of it

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