Skip to content

Commit cfc3cef

Browse files
committed
Set default=True if space/margin passed to register_colors
1 parent 444c409 commit cfc3cef

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

proplot/colors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,17 +613,19 @@ def _load_colors(path, ignore_base=True, warn_on_failure=True):
613613
return loaded
614614

615615

616-
def _standardize_colors(input, space='hcl', margin=0.10):
616+
def _standardize_colors(input, space, margin):
617617
"""
618618
Standardize the input colors.
619619
620620
Parameters
621621
----------
622+
input : dict
623+
The colors.
622624
space : optional
623625
The colorspace used to filter colors.
624626
margin : optional
625-
The proportional margin required for "unique" colors (e.g. 0.10
626-
represents 36 hue units, 10 saturation units, 10 luminance units).
627+
The proportional margin required for unique colors (e.g. 0.1
628+
is 36 hue units, 10 saturation units, 10 luminance units).
627629
"""
628630
output = {}
629631
colors = []

proplot/config.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def register_cycles(*args, user=None, default=False):
642642

643643

644644
@docstring._snippet_manager
645-
def register_colors(*args, user=None, default=False, space='hcl', margin=0.1, **kwargs):
645+
def register_colors(*args, user=None, default=False, space=None, margin=None, **kwargs):
646646
"""
647647
Register named colors. This is called on import.
648648
@@ -651,13 +651,15 @@ def register_colors(*args, user=None, default=False, space='hcl', margin=0.1, **
651651
%(rc.color_args)s
652652
%(rc.color_params)s
653653
space : {'hcl', 'hsl', 'hpl'}, optional
654-
Ignored if `default` is ``False``. The colorspace used to select "perceptually
655-
distinct" colors from the XKCD `color survey <https://xkcd.com/color/rgb/>`_.
654+
The colorspace used to select "perceptually distinct" colors from the XKCD
655+
`color survey <https://xkcd.com/color/rgb/>`__. Default is ``'hcl'``. If
656+
passed then `default` is set to ``True``.
656657
margin : float, optional
657-
Ignored if `default` is ``False``. The margin by which the normalized hue,
658-
saturation, and luminance of each XKCD color must differ from the channel
659-
values of the other XKCD colors to be deemed "perceptually distinct" and
660-
registered. Must be between ``0`` and ``1``. ``0`` will register all colors.
658+
The margin by which the normalized hue, saturation, and luminance of each
659+
XKCD color must differ from the channel values of the other XKCD colors to
660+
be deemed "perceptually distinct" and registered. Must fall between ``0``
661+
and ``1`` (``0`` will register all colors). Default is ``0.1``. If
662+
passed then `default` is set to ``True``.
661663
**kwargs
662664
Additional color name specifications passed as keyword arguments rather
663665
than positional dictionaries.
@@ -671,6 +673,9 @@ def register_colors(*args, user=None, default=False, space='hcl', margin=0.1, **
671673
"""
672674
# Add in base colors and CSS4 colors so user has no surprises
673675
from . import colors as pcolors
676+
default = _not_none(space is not None, margin is not None, default)
677+
margin = _not_none(margin, 0.1)
678+
space = _not_none(space, 'hcl')
674679
if default:
675680
pcolors._color_database.clear() # MutableMapping ensures cache also clears
676681
for src in (mcolors.CSS4_COLORS, pcolors.COLORS_BASE):
@@ -708,7 +713,7 @@ def register_colors(*args, user=None, default=False, space='hcl', margin=0.1, **
708713

709714
# Add xkcd colors after filtering
710715
elif cat == 'xkcd':
711-
loaded = pcolors._standardize_colors(loaded, space=space, margin=margin)
716+
loaded = pcolors._standardize_colors(loaded, space, margin)
712717
pcolors._color_database.update(loaded)
713718
pcolors.COLORS_XKCD.update(loaded)
714719

0 commit comments

Comments
 (0)