Skip to content

Commit 1e0205f

Browse files
authored
Merge pull request #160 from lukelbd/rename-cmapdict
Rename _cmapdict to _cmap_database
2 parents eb97323 + 5abd460 commit 1e0205f

File tree

5 files changed

+35
-32
lines changed

5 files changed

+35
-32
lines changed

proplot/colors.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
from .internals import docstring, warnings, _not_none
1717
from .utils import to_rgb, to_xyz
1818
if hasattr(mcm, '_cmap_registry'):
19-
_cmapdict_attr = '_cmap_registry'
19+
_cmap_database_attr = '_cmap_registry'
2020
else:
21-
_cmapdict_attr = 'cmap_d'
22-
_cmapdict = getattr(mcm, _cmapdict_attr)
21+
_cmap_database_attr = 'cmap_d'
22+
_cmap_database = getattr(mcm, _cmap_database_attr)
2323

2424

2525
__all__ = [
@@ -2166,7 +2166,7 @@ def __getitem__(self, key):
21662166
and isinstance(rgb[1], Number) and isinstance(rgb[0], str)
21672167
):
21682168
try:
2169-
cmap = _cmapdict[rgb[0]]
2169+
cmap = _cmap_database[rgb[0]]
21702170
except (TypeError, KeyError):
21712171
pass
21722172
else:
@@ -2199,11 +2199,11 @@ def _get_cmap(name=None, lut=None):
21992199
if isinstance(name, mcolors.Colormap):
22002200
return name
22012201
try:
2202-
cmap = _cmapdict[name]
2202+
cmap = _cmap_database[name]
22032203
except KeyError:
22042204
raise KeyError(
22052205
f'Invalid colormap name {name!r}. Valid names are: '
2206-
+ ', '.join(map(repr, _cmapdict)) + '.'
2206+
+ ', '.join(map(repr, _cmap_database)) + '.'
22072207
)
22082208
if lut is not None:
22092209
cmap = cmap._resample(lut)
@@ -2349,13 +2349,13 @@ def _sanitize_key(self, key, mirror=True):
23492349
# Replace colormap database with custom database
23502350
if mcm.get_cmap is not _get_cmap:
23512351
mcm.get_cmap = _get_cmap
2352-
if not isinstance(_cmapdict, ColormapDatabase):
2353-
_cmapdict = {
2354-
key: value for key, value in _cmapdict.items()
2352+
if not isinstance(_cmap_database, ColormapDatabase):
2353+
_cmap_database = {
2354+
key: value for key, value in _cmap_database.items()
23552355
if key[-2:] != '_r' and key[-8:] != '_shifted'
23562356
}
2357-
_cmapdict = ColormapDatabase(_cmapdict)
2358-
setattr(mcm, _cmapdict_attr, _cmapdict)
2357+
_cmap_database = ColormapDatabase(_cmap_database)
2358+
setattr(mcm, _cmap_database_attr, _cmap_database)
23592359

23602360
# Deprecations
23612361
CmapDict = warnings._rename_obj('CmapDict', ColormapDatabase)

proplot/config.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -953,11 +953,11 @@ def _update_color_cycle(key, value):
953953
else:
954954
cycle, rgbcycle = value, rc_quick['rgbcycle']
955955
try:
956-
colors = pcolors._cmapdict[cycle].colors
956+
colors = pcolors._cmap_database[cycle].colors
957957
except (KeyError, AttributeError):
958958
return {}, {}, {}
959959
cycles = sorted(
960-
name for name, cmap in pcolors._cmapdict.items()
960+
name for name, cmap in pcolors._cmap_database.items()
961961
if isinstance(cmap, pcolors.ListedColormap)
962962
)
963963
raise ValueError(
@@ -1217,7 +1217,7 @@ def register_cmaps(user=True, default=False):
12171217
'phase', 'graycycle', 'romao', 'broco', 'corko', 'viko',
12181218
):
12191219
cmap.set_cyclic(True)
1220-
pcolors._cmapdict[cmap.name] = cmap
1220+
pcolors._cmap_database[cmap.name] = cmap
12211221

12221222

12231223
@docstring.add_snippets
@@ -1241,7 +1241,7 @@ def register_cycles(user=True, default=False):
12411241
cmap = pcolors.ListedColormap.from_file(path, warn_on_failure=True)
12421242
if not cmap:
12431243
continue
1244-
pcolors._cmapdict[cmap.name] = cmap
1244+
pcolors._cmap_database[cmap.name] = cmap
12451245

12461246

12471247
@docstring.add_snippets
@@ -1418,10 +1418,13 @@ def register_fonts():
14181418
os.environ['TTFPATH'] += ':' + paths
14191419
mfonts._rebuild()
14201420

1421-
# Remove ttc files *after* rebuild
1421+
# Remove ttc files and 'Thin' fonts *after* rebuild
1422+
# NOTE: 'Thin' filter is ugly kludge but without this matplotlib picks up on
1423+
# Roboto thin ttf files installed on the RTD server when compiling docs.
14221424
mfonts.fontManager.ttflist = [
14231425
font for font in mfonts.fontManager.ttflist
14241426
if os.path.splitext(font.fname)[1] != '.ttc'
1427+
or 'Thin' in os.path.basename(font.fname)
14251428
]
14261429

14271430

@@ -1441,10 +1444,10 @@ def register_fonts():
14411444

14421445
# Convert colormaps that *should* be LinearSegmented from Listed
14431446
for _name in ('viridis', 'plasma', 'inferno', 'magma', 'cividis', 'twilight'):
1444-
_cmap = pcolors._cmapdict.get(_name, None)
1447+
_cmap = pcolors._cmap_database.get(_name, None)
14451448
if _cmap and isinstance(_cmap, pcolors.ListedColormap):
1446-
del pcolors._cmapdict[_name]
1447-
pcolors._cmapdict[_name] = pcolors.LinearSegmentedColormap.from_list(
1449+
del pcolors._cmap_database[_name]
1450+
pcolors._cmap_database[_name] = pcolors.LinearSegmentedColormap.from_list(
14481451
_name, _cmap.colors, cyclic=(_name == 'twilight')
14491452
)
14501453

@@ -1472,7 +1475,7 @@ def register_fonts():
14721475
# image.lut. We have to register colormaps and cycles first so that the 'cycle'
14731476
# property accepts named cycles registered by ProPlot. No performance hit here.
14741477
lut = rc['image.lut']
1475-
for cmap in pcolors._cmapdict.values():
1478+
for cmap in pcolors._cmap_database.values():
14761479
if isinstance(cmap, mcolors.LinearSegmentedColormap):
14771480
cmap.N = lut
14781481

proplot/constructor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def _parse_modification(key, value):
459459
arg = pcolors.LinearSegmentedColormap.from_file(arg)
460460
else:
461461
try:
462-
arg = pcolors._cmapdict[arg]
462+
arg = pcolors._cmap_database[arg]
463463
except KeyError:
464464
pass
465465

@@ -507,11 +507,11 @@ def _parse_modification(key, value):
507507
message = f'Invalid colormap, color cycle, or color {arg!r}.'
508508
if isinstance(arg, str) and arg[:1] != '#':
509509
cmaps = ', '.join(sorted(
510-
repr(key) for key, value in pcolors._cmapdict.items()
510+
repr(key) for key, value in pcolors._cmap_database.items()
511511
if isinstance(value, pcolors.LinearSegmentedColormap)
512512
))
513513
cycles = ', '.join(sorted(
514-
repr(key) for key, value in pcolors._cmapdict.items()
514+
repr(key) for key, value in pcolors._cmap_database.items()
515515
if isinstance(value, pcolors.ListedColormap)
516516
))
517517
colors = ', '.join(sorted(
@@ -562,7 +562,7 @@ def _parse_modification(key, value):
562562
name = cmap.name # may have been modified by e.g. .shifted()
563563
else:
564564
cmap.name = name
565-
pcolors._cmapdict[name] = cmap
565+
pcolors._cmap_database[name] = cmap
566566
if save:
567567
save_kw = save_kw or {}
568568
cmap.save(**save_kw)

proplot/demos.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _draw_bars(
223223
iax += 1
224224
ax.set_visible(False)
225225
ax = axs[iax]
226-
cmap = pcolors._cmapdict[name]
226+
cmap = pcolors._cmap_database[name]
227227
if N is not None:
228228
cmap = cmap.copy(N=N)
229229
ax.colorbar(
@@ -662,8 +662,8 @@ def show_cmaps(*args, **kwargs):
662662
]
663663
else:
664664
names = [
665-
name for name in pcolors._cmapdict.keys() if
666-
isinstance(pcolors._cmapdict[name], pcolors.LinearSegmentedColormap)
665+
name for name in pcolors._cmap_database.keys() if
666+
isinstance(pcolors._cmap_database[name], pcolors.LinearSegmentedColormap)
667667
]
668668

669669
# Return figure of colorbars
@@ -705,8 +705,8 @@ def show_cycles(*args, **kwargs):
705705
]
706706
else:
707707
names = [
708-
name for name in pcolors._cmapdict.keys() if
709-
isinstance(pcolors._cmapdict[name], pcolors.ListedColormap)
708+
name for name in pcolors._cmap_database.keys() if
709+
isinstance(pcolors._cmap_database[name], pcolors.ListedColormap)
710710
]
711711

712712
# Return figure of colorbars

proplot/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55
import re
66
import numpy as np
7-
import matplotlib.cm as mcm
87
import matplotlib.colors as mcolors
98
from matplotlib import rcParams
109
from numbers import Number, Integral
@@ -364,11 +363,12 @@ def to_rgb(color, space='rgb', cycle=None, alpha=False):
364363
# Convert color cycle strings
365364
if isinstance(color, str) and re.match(r'\AC[0-9]\Z', color):
366365
if isinstance(cycle, str):
366+
from .colors import _cmap_database
367367
try:
368-
cycle = mcm.cmap_d[cycle].colors
368+
cycle = _cmap_database[cycle].colors
369369
except (KeyError, AttributeError):
370370
cycles = sorted(
371-
name for name, cmap in mcm.cmap_d.items()
371+
name for name, cmap in _cmap_database.items()
372372
if isinstance(cmap, mcolors.ListedColormap)
373373
)
374374
raise ValueError(

0 commit comments

Comments
 (0)