Skip to content

Commit 79be642

Browse files
committed
Add 'categories' kwarg to show_(cmaps|cycles)
1 parent 8922d6d commit 79be642

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

proplot/styletools.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,7 +3311,8 @@ def register_fonts():
33113311

33123312

33133313
def _draw_bars(
3314-
names, *, source, unknown='User', length=4.0, width=0.2, N=None
3314+
names, *, source, unknown='User', categories=None,
3315+
length=4.0, width=0.2, N=None
33153316
):
33163317
"""
33173318
Draw colorbars for "colormaps" and "color cycles". This is called by
@@ -3329,6 +3330,18 @@ def _draw_bars(
33293330
if names_cat:
33303331
cmapdict[cat] = names_cat
33313332

3333+
# Filter out certain categories
3334+
if categories is None:
3335+
categories = source.keys() - {'MATLAB', 'GNUplot', 'GIST', 'Other'}
3336+
if any(cat not in source for cat in categories):
3337+
raise ValueError(
3338+
f'Invalid categories {categories!r}. Options are: '
3339+
+ ', '.join(map(repr, source)) + '.'
3340+
)
3341+
for cat in (*cmapdict,):
3342+
if cat not in categories:
3343+
cmapdict.pop(cat)
3344+
33323345
# Draw figure
33333346
from . import subplots
33343347
naxs = len(cmapdict) + sum(map(len, cmapdict.values()))
@@ -3351,17 +3364,17 @@ def _draw_bars(
33513364
ax = axs[iax]
33523365
cmap = mcm.cmap_d[name]
33533366
if N is not None:
3354-
cmap = cmap.updated(N=N)
3355-
ax.colorbar( # TODO: support this in public API
3356-
cmap, loc='_fill',
3367+
cmap = cmap.copy(N=N)
3368+
ax.colorbar(
3369+
cmap, loc='fill',
33573370
orientation='horizontal', locator='null', linewidth=0
33583371
)
33593372
ax.text(
33603373
0 - (rcParams['axes.labelpad'] / 72) / length, 0.45, name,
33613374
ha='right', va='center', transform='axes',
33623375
)
33633376
if imap == 0:
3364-
ax.set_title(cat)
3377+
ax.set_title(cat, weight='bold')
33653378
nbars += len(names)
33663379
return fig
33673380

@@ -3766,6 +3779,12 @@ def show_cmaps(*args, **kwargs):
37663779
Category name for colormaps that are unknown to ProPlot. The
37673780
default is ``'User'``. Set this to ``False`` to hide
37683781
unknown colormaps.
3782+
categories : list of str, optional
3783+
Category names to be shown in the table. By default, every category
3784+
is shown except the ``'MATLAB'``, ``'GNUplot'``, ``'GIST'``,
3785+
and ``'Other'`` categories. Use of these colormaps is discouraged,
3786+
because they contain a variety of non-uniform colormaps (see
3787+
:ref:`Perceptually uniform colormaps` for details).
37693788
length : float or str, optional
37703789
The length of the colorbars. Units are interpreted by
37713790
`~proplot.utils.units`.
@@ -3778,9 +3797,9 @@ def show_cmaps(*args, **kwargs):
37783797
`~proplot.subplots.Figure`
37793798
The figure.
37803799
"""
3781-
# Have colormaps separated into categories
3800+
# Get the list of colormaps
37823801
if args:
3783-
names = [Colormap(cmap).name for cmap in args]
3802+
names = [Colormap(cmap, to_listed=True).name for cmap in args]
37843803
else:
37853804
names = [
37863805
name for name in mcm.cmap_d.keys() if
@@ -3806,6 +3825,9 @@ def show_cycles(*args, **kwargs):
38063825
Category name for cycles that are unknown to ProPlot. The
38073826
default is ``'User'``. Set this to ``False`` to hide
38083827
unknown colormaps.
3828+
categories : list of str, optional
3829+
Category names to be shown in the table. By default, every
3830+
category is shown.
38093831
length : float or str, optional
38103832
The length of the colorbars. Units are interpreted by
38113833
`~proplot.utils.units`.
@@ -3820,7 +3842,7 @@ def show_cycles(*args, **kwargs):
38203842
"""
38213843
# Get the list of cycles
38223844
if args:
3823-
names = [cmap.name for cmap in args]
3845+
names = [Colormap(cmap).name for cmap in args]
38243846
else:
38253847
names = [
38263848
name for name in mcm.cmap_d.keys() if

0 commit comments

Comments
 (0)