MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / MultivarColormap

Class MultivarColormap

lib/matplotlib/colors.py:1424–1676  ·  view source on GitHub ↗

Class for holding multiple `~matplotlib.colors.Colormap` for use in a `~matplotlib.cm.ScalarMappable` object

Source from the content-addressed store, hash-verified

1422
1423
1424class MultivarColormap:
1425 """
1426 Class for holding multiple `~matplotlib.colors.Colormap` for use in a
1427 `~matplotlib.cm.ScalarMappable` object
1428 """
1429 def __init__(self, colormaps, combination_mode, name='multivariate colormap'):
1430 """
1431 Parameters
1432 ----------
1433 colormaps: list or tuple of `~matplotlib.colors.Colormap` objects
1434 The individual colormaps that are combined
1435 combination_mode: str, 'sRGB_add' or 'sRGB_sub'
1436 Describe how colormaps are combined in sRGB space
1437
1438 - If 'sRGB_add' -> Mixing produces brighter colors
1439 `sRGB = sum(colors)`
1440 - If 'sRGB_sub' -> Mixing produces darker colors
1441 `sRGB = 1 - sum(1 - colors)`
1442 name : str, optional
1443 The name of the colormap family.
1444 """
1445 self.name = name
1446
1447 if not np.iterable(colormaps) \
1448 or len(colormaps) == 1 \
1449 or isinstance(colormaps, str):
1450 raise ValueError("A MultivarColormap must have more than one colormap.")
1451 colormaps = list(colormaps) # ensure cmaps is a list, i.e. not a tuple
1452 for i, cmap in enumerate(colormaps):
1453 if isinstance(cmap, str):
1454 colormaps[i] = mpl.colormaps[cmap]
1455 elif not isinstance(cmap, Colormap):
1456 raise ValueError("colormaps must be a list of objects that subclass"
1457 " Colormap or a name found in the colormap registry.")
1458
1459 self._colormaps = colormaps
1460 _api.check_in_list(['sRGB_add', 'sRGB_sub'], combination_mode=combination_mode)
1461 self._combination_mode = combination_mode
1462 self.n_variates = len(colormaps)
1463 self._rgba_bad = (0.0, 0.0, 0.0, 0.0) # If bad, don't paint anything.
1464
1465 def __call__(self, X, alpha=None, bytes=False, clip=True):
1466 r"""
1467 Parameters
1468 ----------
1469 X : tuple (X0, X1, ...) of length equal to the number of colormaps
1470 X0, X1 ...:
1471 float or int, `~numpy.ndarray` or scalar
1472 The data value(s) to convert to RGBA.
1473 For floats, *Xi...* should be in the interval ``[0.0, 1.0]`` to
1474 return the RGBA values ``X*100`` percent along the Colormap line.
1475 For integers, *Xi...* should be in the interval ``[0, self[i].N)`` to
1476 return RGBA values *indexed* from colormap [i] with index ``Xi``, where
1477 self[i] is colormap i.
1478 alpha : float or array-like or None
1479 Alpha must be a scalar between 0 and 1, a sequence of such
1480 floats with shape matching *Xi*, or None.
1481 bytes : bool, default: False

Callers 1

_cm_multivar.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…