Return a copy of the `MultivarColormap` with modified out-of-range attributes. The *bad* keyword modifies the copied `MultivarColormap` while *under* and *over* modifies the attributes of the copied component colormaps. Note that *under* and *over* colors are subjec
(self, *, bad=None, under=None, over=None)
| 1600 | return new_cmap |
| 1601 | |
| 1602 | def with_extremes(self, *, bad=None, under=None, over=None): |
| 1603 | """ |
| 1604 | Return a copy of the `MultivarColormap` with modified out-of-range attributes. |
| 1605 | |
| 1606 | The *bad* keyword modifies the copied `MultivarColormap` while *under* and |
| 1607 | *over* modifies the attributes of the copied component colormaps. |
| 1608 | Note that *under* and *over* colors are subject to the mixing rules determined |
| 1609 | by the *combination_mode*. |
| 1610 | |
| 1611 | Parameters |
| 1612 | ---------- |
| 1613 | bad: :mpltype:`color`, default: None |
| 1614 | If Matplotlib color, the bad value is set accordingly in the copy |
| 1615 | |
| 1616 | under tuple of :mpltype:`color`, default: None |
| 1617 | If tuple, the `under` value of each component is set with the values |
| 1618 | from the tuple. |
| 1619 | |
| 1620 | over tuple of :mpltype:`color`, default: None |
| 1621 | If tuple, the `over` value of each component is set with the values |
| 1622 | from the tuple. |
| 1623 | |
| 1624 | Returns |
| 1625 | ------- |
| 1626 | MultivarColormap |
| 1627 | copy of self with attributes set |
| 1628 | |
| 1629 | """ |
| 1630 | new_cm = self.copy() |
| 1631 | if bad is not None: |
| 1632 | new_cm._rgba_bad = to_rgba(bad) |
| 1633 | if under is not None: |
| 1634 | if not np.iterable(under) or len(under) != len(new_cm): |
| 1635 | raise ValueError("*under* must contain a color for each scalar colormap" |
| 1636 | f" i.e. be of length {len(new_cm)}.") |
| 1637 | else: |
| 1638 | for c, b in zip(new_cm, under): |
| 1639 | # in-place change is ok, since we've just created c as a copy |
| 1640 | c._set_extremes(under=b) |
| 1641 | if over is not None: |
| 1642 | if not np.iterable(over) or len(over) != len(new_cm): |
| 1643 | raise ValueError("*over* must contain a color for each scalar colormap" |
| 1644 | f" i.e. be of length {len(new_cm)}.") |
| 1645 | else: |
| 1646 | for c, b in zip(new_cm, over): |
| 1647 | # in-place change is ok, since we've just created c as a copy |
| 1648 | c._set_extremes(over=b) |
| 1649 | return new_cm |
| 1650 | |
| 1651 | @property |
| 1652 | def combination_mode(self): |