Skip to content

Commit b90bee8

Browse files
committed
Fix issue where xkcd color overwrites base 'yellow'
1 parent 6175296 commit b90bee8

2 files changed

Lines changed: 15 additions & 30 deletions

File tree

proplot/colors.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -567,18 +567,14 @@ def _make_lookup_table(N, data, gamma=1.0, inverse=False):
567567
return lut
568568

569569

570-
def _load_colors(path, ignore_base=True, warn_on_failure=True):
570+
def _load_colors(path, warn_on_failure=True):
571571
"""
572572
Read colors from the input file.
573573
574574
Parameters
575575
----------
576-
ignore_base : bool, optional
577-
If ``True``, ignore colors matching "base" color names like
578-
``'red'`` and ``'blue'``.
579576
warn_on_failure : bool, optional
580-
If ``True``, issue a warning when loading fails instead of
581-
raising an error.
577+
If ``True``, issue a warning when loading fails instead of raising an error.
582578
"""
583579
# Warn or raise error (matches Colormap._from_file behavior)
584580
if not os.path.exists(path):
@@ -605,10 +601,8 @@ def _load_colors(path, ignore_base=True, warn_on_failure=True):
605601
f'Lines must be formatted as "name: hexcolor".'
606602
)
607603
continue
608-
# Never overwrite "base" colors with proplot defaults
604+
# Add color
609605
name, color = pair
610-
if ignore_base and name in COLORS_BASE:
611-
continue
612606
loaded[name] = color
613607

614608
return loaded

proplot/config.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -697,28 +697,19 @@ def register_colors(*args, user=None, default=False, space=None, margin=None, **
697697

698698
# Load colors from file and get their HCL values
699699
# NOTE: Colors that come *later* overwrite colors that come earlier.
700+
srcs = {'opencolor': pcolors.COLORS_OPEN, 'xkcd': pcolors.COLORS_XKCD}
700701
for i, path in _iter_data_objects('colors', *paths, user=user, default=default):
701-
# Read colors
702-
loaded = pcolors._load_colors(path, ignore_base=(i == 0), warn_on_failure=True)
703-
704-
# Add user colors
705-
cat, _ = os.path.splitext(os.path.basename(path))
706-
if i != 0:
707-
pcolors._color_database.update(loaded)
708-
709-
# Add open-color colors
710-
elif cat == 'opencolor':
711-
pcolors._color_database.update(loaded)
712-
pcolors.COLORS_OPEN.update(loaded)
713-
714-
# Add xkcd colors after filtering
715-
elif cat == 'xkcd':
716-
loaded = pcolors._standardize_colors(loaded, space, margin)
717-
pcolors._color_database.update(loaded)
718-
pcolors.COLORS_XKCD.update(loaded)
719-
720-
else:
721-
raise RuntimeError(f'Unknown proplot color database {path!r}.')
702+
loaded = pcolors._load_colors(path, warn_on_failure=True)
703+
if i == 0:
704+
cat, _ = os.path.splitext(os.path.basename(path))
705+
if cat not in srcs:
706+
raise RuntimeError(f'Unknown proplot color database {path!r}.')
707+
src = srcs[cat]
708+
if cat == 'xkcd':
709+
loaded = pcolors._standardize_colors(loaded, space, margin)
710+
loaded = {k: c for k, c in loaded.items() if k not in pcolors.COLORS_BASE}
711+
src.update(loaded) # needed for demos.show_colors()
712+
pcolors._color_database.update(loaded)
722713

723714

724715
@docstring._snippet_manager

0 commit comments

Comments
 (0)