3939]
4040
4141# Colormap stuff
42+ CYCLES_TABLE = {
43+ 'Matplotlib originals' : (
44+ 'default' , 'classic' ,
45+ ),
46+ 'Matplotlib stylesheets' : (
47+ 'colorblind' , 'colorblind10' , 'ggplot' , 'bmh' , 'solarized' , '538' ,
48+ ),
49+ 'ColorBrewer2.0 qualitative' : (
50+ 'Accent' , 'Dark2' ,
51+ 'Paired' , 'Pastel1' , 'Pastel2' ,
52+ 'Set1' , 'Set2' , 'Set3' ,
53+ ),
54+ 'Other qualitative' : (
55+ 'FlatUI' , 'Qual1' , 'Qual2' , 'Viz' ,
56+ ),
57+ 'ProPlot originals' : (
58+ 'Cool' , 'Warm' , 'Hot' ,
59+ 'Floral' , 'Contrast' , 'Sharp' ,
60+ ),
61+ }
4262CMAPS_TABLE = {
4363 # Assorted origin, but these belong together
4464 'Grayscale' : (
@@ -3164,12 +3184,20 @@ def register_fonts():
31643184 fonts [:] = [* fonts_proplot , * fonts_system ]
31653185
31663186
3167- def _draw_bars (cmapdict , length = 4.0 , width = 0.2 ):
3187+ def _draw_bars (names , * , source , unknown = 'User' , length = 4.0 , width = 0.2 ):
31683188 """
31693189 Draw colorbars for "colormaps" and "color cycles". This is called by
31703190 `show_cycles` and `show_cmaps`.
31713191 """
3172- # Figure
3192+ # Categorize the input names
3193+ cmapdict = {}
3194+ names_all = list (map (str .lower , names ))
3195+ names_known = list (map (str .lower , sum (map (list , source .values ()), [])))
3196+ cmapdict [unknown ] = [name for name in names if name not in names_known ]
3197+ for cat , names in source .items ():
3198+ cmapdict [cat ] = [name for name in names if name .lower () in names_all ]
3199+
3200+ # Draw figure
31733201 from . import subplots
31743202 naxs = len (cmapdict ) + sum (map (len , cmapdict .values ()))
31753203 fig , axs = subplots (
@@ -3526,10 +3554,10 @@ def _color_filter(i, hcl): # noqa: E306
35263554 return figs
35273555
35283556
3529- def show_cmaps (* args , N = None , unknown = 'User' , ** kwargs ):
3557+ def show_cmaps (* args , N = None , ** kwargs ):
35303558 """
3531- Generate a table of the registered colormaps or the input colormaps.
3532- Adapted from `this example \
3559+ Generate a table of the registered colormaps or the input colormaps
3560+ categorized by source. Adapted from `this example \
35333561 <http://matplotlib.org/examples/color/colormaps_reference.html>`__.
35343562
35353563 Parameters
@@ -3564,26 +3592,24 @@ def show_cmaps(*args, N=None, unknown='User', **kwargs):
35643592 isinstance (mcm .cmap_d [name ], LinearSegmentedColormap )
35653593 ]
35663594
3567- # Get dictionary of registered colormaps and their categories
3568- cmapdict = {}
3569- names_all = list (map (str .lower , names ))
3570- names_known = sum (map (list , CMAPS_TABLE .values ()), [])
3571- cmapdict [unknown ] = [name for name in names if name not in names_known ]
3572- for cat , names in CMAPS_TABLE .items ():
3573- cmapdict [cat ] = [name for name in names if name .lower () in names_all ]
3574-
35753595 # Return figure of colorbars
3576- return _draw_bars (cmapdict , ** kwargs )
3596+ kwargs .setdefault ('source' , CMAPS_TABLE )
3597+ return _draw_bars (names , ** kwargs )
35773598
35783599
35793600def show_cycles (* args , ** kwargs ):
35803601 """
3581- Generate a table of registered color cycles or the input color cycles.
3602+ Generate a table of registered color cycles or the input color cycles
3603+ categorized by source. Adapted from `this example \
3604+ <http://matplotlib.org/examples/color/colormaps_reference.html>`__.
35823605
35833606 Parameters
35843607 ----------
35853608 *args : colormap-spec, optional
35863609 Cycle names or objects.
3610+ unknown : str, optional
3611+ Category name for cycles that are unknown to ProPlot. The
3612+ default is ``'User'``.
35873613 length : float or str, optional
35883614 The length of the colorbars. Units are interpreted by
35893615 `~proplot.utils.units`.
@@ -3606,8 +3632,8 @@ def show_cycles(*args, **kwargs):
36063632 ]
36073633
36083634 # Return figure of colorbars
3609- cmapdict = { 'Color cycles' : names }
3610- return _draw_bars (cmapdict , ** kwargs )
3635+ kwargs . setdefault ( 'source' , CYCLES_TABLE )
3636+ return _draw_bars (names , ** kwargs )
36113637
36123638
36133639def show_fonts (* args , size = 12 , text = None ):
0 commit comments