r""" Parameters ---------- X : tuple (X0, X1), X0 and X1: float or int or array-like The data value(s) to convert to RGBA. - For floats, *X* should be in the interval ``[0.0, 1.0]`` to return the RGBA values ``X*100`` percent along the C
(self, X, alpha=None, bytes=False)
| 1729 | self.colorbar_extend = False''' |
| 1730 | |
| 1731 | def __call__(self, X, alpha=None, bytes=False): |
| 1732 | r""" |
| 1733 | Parameters |
| 1734 | ---------- |
| 1735 | X : tuple (X0, X1), X0 and X1: float or int or array-like |
| 1736 | The data value(s) to convert to RGBA. |
| 1737 | |
| 1738 | - For floats, *X* should be in the interval ``[0.0, 1.0]`` to |
| 1739 | return the RGBA values ``X*100`` percent along the Colormap. |
| 1740 | - For integers, *X* should be in the interval ``[0, Colormap.N)`` to |
| 1741 | return RGBA values *indexed* from the Colormap with index ``X``. |
| 1742 | |
| 1743 | alpha : float or array-like or None, default: None |
| 1744 | Alpha must be a scalar between 0 and 1, a sequence of such |
| 1745 | floats with shape matching X0, or None. |
| 1746 | bytes : bool, default: False |
| 1747 | If False (default), the returned RGBA values will be floats in the |
| 1748 | interval ``[0, 1]`` otherwise they will be `numpy.uint8`\s in the |
| 1749 | interval ``[0, 255]``. |
| 1750 | |
| 1751 | Returns |
| 1752 | ------- |
| 1753 | Tuple of RGBA values if X is scalar, otherwise an array of |
| 1754 | RGBA values with a shape of ``X.shape + (4, )``. |
| 1755 | """ |
| 1756 | |
| 1757 | if len(X) != 2: |
| 1758 | raise ValueError( |
| 1759 | f'For a `BivarColormap` the data must have a first dimension ' |
| 1760 | f'2, not {len(X)}') |
| 1761 | |
| 1762 | if not self._isinit: |
| 1763 | self._init() |
| 1764 | |
| 1765 | X0 = np.ma.array(X[0], copy=True) |
| 1766 | X1 = np.ma.array(X[1], copy=True) |
| 1767 | # clip to shape of colormap, circle square, etc. |
| 1768 | self._clip((X0, X1)) |
| 1769 | |
| 1770 | # Native byteorder is faster. |
| 1771 | if not X0.dtype.isnative: |
| 1772 | X0 = X0.byteswap().view(X0.dtype.newbyteorder()) |
| 1773 | if not X1.dtype.isnative: |
| 1774 | X1 = X1.byteswap().view(X1.dtype.newbyteorder()) |
| 1775 | |
| 1776 | if X0.dtype.kind == "f": |
| 1777 | X0 *= self.N |
| 1778 | # xa == 1 (== N after multiplication) is not out of range. |
| 1779 | X0[X0 == self.N] = self.N - 1 |
| 1780 | |
| 1781 | if X1.dtype.kind == "f": |
| 1782 | X1 *= self.M |
| 1783 | # xa == 1 (== N after multiplication) is not out of range. |
| 1784 | X1[X1 == self.M] = self.M - 1 |
| 1785 | |
| 1786 | # Pre-compute the masks before casting to int (which can truncate) |
| 1787 | mask_outside = (X0 < 0) | (X1 < 0) | (X0 >= self.N) | (X1 >= self.M) |
| 1788 | # If input was masked, get the bad mask from it; else mask out nans. |