@@ -2644,12 +2644,14 @@ def _load_cmap_cycle(filename, cmap=False):
26442644@_timer
26452645def register_cmaps ():
26462646 """
2647- Adds colormaps packaged with ProPlot or saved to the ``~/.proplot/cmaps``
2647+ Add colormaps packaged with ProPlot or saved to the ``~/.proplot/cmaps``
26482648 folder. This is called on import. Maps are registered according to their
26492649 filenames -- for example, ``name.xyz`` will be registered as ``'name'``.
2650- Use `show_cmaps` to generate a table of the registered colormaps
26512650
2652- Valid extensions are described in the below table.
2651+ This is called on import. Use `show_cmaps` to generate a table of the
2652+ registered colormaps
2653+
2654+ Valid extensions are listed in the below table.
26532655
26542656 ===================== =============================================================================================================================================================================================================
26552657 Extension Description
@@ -2704,13 +2706,14 @@ def register_cmaps():
27042706@_timer
27052707def register_cycles ():
27062708 """
2707- Adds color cycles packaged with ProPlot or saved to the ``~/.proplot/cycles``
2709+ Add color cycles packaged with ProPlot or saved to the ``~/.proplot/cycles``
27082710 folder. This is called on import. Cycles are registered according to their
27092711 filenames -- for example, ``name.hex`` will be registered under the name
27102712 ``'name'`` as a `~matplotlib.colors.ListedColormap` map (see `Cycle` for
2711- details). Use `show_cycles` to generate a table of the registered cycles.
2713+ details).
27122714
2713- For valid file formats, see `register_cmaps`.
2715+ This is called on import. Use `show_cycles` to generate a table of the
2716+ registered cycles. For valid file formats, see `register_cmaps`.
27142717 """
27152718 # Empty out user-accessible cycle list
27162719 cycles .clear ()
@@ -2746,10 +2749,15 @@ def register_cycles():
27462749@_timer
27472750def register_colors (nmax = np .inf ):
27482751 """
2749- Reads full database of crowd-sourced XKCD color names and official
2750- Crayola color names, then filters them to be sufficiently "perceptually
2751- distinct" in the HCL colorspace. This is called on import. Use `show_colors`
2752- to generate a table of the resulting filtered colors.
2752+ Add color names packaged with ProPlot or saved to the ``~/.proplot/colors``
2753+ folder. ProPlot loads the crowd-sourced XKCD color
2754+ name database, Crayola crayon color database, and any user input
2755+ files, then filters them to be "perceptually distinct" in the HCL
2756+ colorspace. Files must just have one line per color in the format
2757+ ``name : hex``. Whitespace is ignored.
2758+
2759+ This is called on import. Use `show_colors` to generate a table of the
2760+ resulting colors.
27532761 """
27542762 # Reset native colors dictionary and add some default groups
27552763 # Add in CSS4 so no surprises for user, but we will not encourage this
@@ -2781,7 +2789,7 @@ def register_colors(nmax=np.inf):
27812789 dict_ = {name :color for name ,color in data }
27822790 colordict .update ({'open' : dict_ })
27832791 continue
2784- # Other color dictionaries are filtered, and their names are sanitized
2792+ # Remaining dicts are filtered and their names are sanitized
27852793 i = 0
27862794 dict_ = {}
27872795 ihcls = []
@@ -2803,16 +2811,21 @@ def register_colors(nmax=np.inf):
28032811
28042812 # Remove colors that are 'too similar' by rounding to the nearest n units
28052813 # WARNING: Unique axis argument requires numpy version >=1.13
2806- deleted = 0
2807- hcls = hcls / np .array (scale )
2808- hcls = np .round (hcls / FILTER_THRESH ).astype (np .int64 )
2809- _ , idxs , _ = np .unique (hcls , return_index = True , return_counts = True , axis = 0 ) # get unique rows
2810- for idx ,(cat ,name ) in enumerate (pairs ):
2811- if name not in FILTER_ADD and idx not in idxs :
2812- deleted += 1
2813- else :
2814- colordict [cat ][name ] = _colordict_unfiltered [cat ][name ]
2815- # Add to colors mapping
2814+ if hcls .size > 0 :
2815+ hcls = hcls / np .array (scale )
2816+ hcls = np .round (hcls / FILTER_THRESH ).astype (np .int64 )
2817+ deleted = 0
2818+ _ , idxs , _ = np .unique (hcls ,
2819+ return_index = True ,
2820+ return_counts = True ,
2821+ axis = 0 ) # get unique rows
2822+ for idx ,(cat ,name ) in enumerate (pairs ):
2823+ if name not in FILTER_ADD and idx not in idxs :
2824+ deleted += 1
2825+ else :
2826+ colordict [cat ][name ] = _colordict_unfiltered [cat ][name ]
2827+
2828+ # Update the color converter
28162829 for _ ,kw in colordict .items ():
28172830 mcolors .colorConverter .colors .update (kw )
28182831
0 commit comments