Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23fb63c

Browse files
committed
Update Colorizer/ColorizingArtist to work with MultiNorm
improved testing for colorizer+multinorm Apply suggestions from code review Co-authored-by: Elliott Sales de Andrade <[email protected]> updates based on feedback from @QuLogic
1 parent 352b419 commit 23fb63c

File tree

6 files changed

+478
-76
lines changed

6 files changed

+478
-76
lines changed

lib/matplotlib/cbook.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,21 @@ def safe_masked_invalid(x, copy=False):
694694
try:
695695
xm = np.ma.masked_where(~(np.isfinite(x)), x, copy=False)
696696
except TypeError:
697-
return x
697+
if len(x.dtype.descr) == 1:
698+
# Arrays with dtype 'object' get returned here.
699+
# For example the 'c' kwarg of scatter, which supports multiple types.
700+
# `plt.scatter([3, 4], [2, 5], c=[(1, 0, 0), 'y'])`
701+
return x
702+
else:
703+
# In case of a dtype with multiple fields
704+
# for example image data using a MultiNorm
705+
try:
706+
mask = np.empty(x.shape, dtype=np.dtype('bool, '*len(x.dtype.descr)))
707+
for dd, dm in zip(x.dtype.descr, mask.dtype.descr):
708+
mask[dm[0]] = ~np.isfinite(x[dd[0]])
709+
xm = np.ma.array(x, mask=mask, copy=False)
710+
except TypeError:
711+
return x
698712
return xm
699713

700714

lib/matplotlib/cm.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -239,32 +239,3 @@ def get_cmap(self, cmap):
239239
_multivar_colormaps = ColormapRegistry(multivar_cmaps)
240240

241241
_bivar_colormaps = ColormapRegistry(bivar_cmaps)
242-
243-
244-
def _ensure_cmap(cmap):
245-
"""
246-
Ensure that we have a `.Colormap` object.
247-
248-
For internal use to preserve type stability of errors.
249-
250-
Parameters
251-
----------
252-
cmap : None, str, Colormap
253-
254-
- if a `Colormap`, return it
255-
- if a string, look it up in mpl.colormaps
256-
- if None, look up the default color map in mpl.colormaps
257-
258-
Returns
259-
-------
260-
Colormap
261-
262-
"""
263-
if isinstance(cmap, colors.Colormap):
264-
return cmap
265-
cmap_name = mpl._val_or_rc(cmap, "image.cmap")
266-
# use check_in_list to ensure type stability of the exception raised by
267-
# the internal usage of this (ValueError vs KeyError)
268-
if cmap_name not in _colormaps:
269-
_api.check_in_list(sorted(_colormaps), cmap=cmap_name)
270-
return mpl.colormaps[cmap_name]

0 commit comments

Comments
 (0)