Skip to content

Commit 8b5420d

Browse files
committed
Improve register_colors, never filter user colors
1 parent d55e8cb commit 8b5420d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

proplot/styletools.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,9 +2988,15 @@ def register_colors(nmax=np.inf):
29882988
seen = {*base} # never overwrite base names, e.g. 'blue' and 'b'!
29892989
hcls = []
29902990
data = []
2991-
for path in _get_data_paths('colors'):
2992-
# prefer xkcd
2993-
for file in sorted(glob.glob(os.path.join(path, '*.txt')))[::-1]:
2991+
for i, path in enumerate(_get_data_paths('colors')):
2992+
if i == 0:
2993+
paths = [ # be explicit because categories matter!
2994+
os.path.join(path, base)
2995+
for base in ('xkcd.txt', 'crayola.txt', 'open.txt')
2996+
]
2997+
else:
2998+
paths = sorted(glob.glob(os.path.join(path, '*.txt')))
2999+
for file in paths:
29943000
cat, _ = os.path.splitext(os.path.basename(file))
29953001
with open(file, 'r') as f:
29963002
pairs = [tuple(item.strip() for item in line.split(':'))
@@ -3000,14 +3006,14 @@ def register_colors(nmax=np.inf):
30003006
f'Invalid color names file {file!r}. '
30013007
f'Every line must be formatted as "name: color".')
30023008

3003-
# Add all open colors
3004-
if cat == 'open':
3009+
# Categories for which we add *all* colors
3010+
if cat == 'open' or i == 1:
30053011
dict_ = {name: color for name, color in pairs}
30063012
mcolors.colorConverter.colors.update(dict_)
3007-
colors['open'] = sorted(dict_)
3013+
colors[cat] = sorted(dict_)
30083014
continue
30093015

3010-
# Filter remaining colors to unique ones
3016+
# Filter remaining colors to *unique* colors
30113017
j = 0
30123018
if cat not in dicts:
30133019
dicts[cat] = {}

0 commit comments

Comments
 (0)