File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Crayola crayon colors
2+ # https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors
13almond: #efdecd
24antique brass: #cd9575
35apricot: #fdd9b5
Original file line number Diff line number Diff line change 1+ # Open-color colors
2+ # https://yeun.github.io/open-color/
13gray0: #f8f9fa
24gray1: #f1f3f5
35gray2: #e9ecef
Original file line number Diff line number Diff line change 1+ # XKCD color survey colors
2+ # https://blog.xkcd.com/2010/05/03/color-survey-results/
13purple: #7e1e9c
24green: #15b01a
35blue: #0343df
Original file line number Diff line number Diff line change @@ -3047,16 +3047,25 @@ def register_colors(nmax=np.inf):
30473047 for file in paths :
30483048 cat , _ = os .path .splitext (os .path .basename (file ))
30493049 with open (file , 'r' ) as f :
3050- pairs = [
3051- tuple (item .strip () for item in line .split (':' ))
3052- for line in f .readlines ()
3053- if line .strip () and line .strip ()[0 ] != '#'
3054- ]
3055- if not all (len (pair ) == 2 for pair in pairs ):
3056- raise RuntimeError (
3057- f'Invalid color names file { file !r} . '
3058- f'Every line must be formatted as "name: color".'
3050+ cnt = 0
3051+ hex = re .compile (
3052+ r'\A#(?:[0-9a-fA-F]{3}){1,2}\Z' # ?: prevents capture
30593053 )
3054+ pairs = []
3055+ for line in f .readlines ():
3056+ cnt += 1
3057+ stripped = line .strip ()
3058+ if not stripped or stripped [0 ] == '#' :
3059+ continue
3060+ pair = tuple (item .strip () for item in line .split (':' ))
3061+ if len (pair ) != 2 or not hex .match (pair [1 ]):
3062+ _warn_proplot (
3063+ f'Illegal line #{ cnt } in file { file !r} :\n '
3064+ f'{ line !r} \n '
3065+ f'Lines must be formatted as "name: hexcolor".'
3066+ )
3067+ continue
3068+ pairs .append (pair )
30603069
30613070 # Categories for which we add *all* colors
30623071 if cat == 'opencolor' or i == 1 :
You can’t perform that action at this time.
0 commit comments