Return a FuncFormatter that maps self.values elements back to the original value as a string. Useful with plt.colorbar. Examples -------- >>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3]) >>> aa = _Normalize(a, width=(0, 0.5, 1)) >>> aa._lookup
(self)
| 1629 | |
| 1630 | @property |
| 1631 | def format(self) -> FuncFormatter: |
| 1632 | """ |
| 1633 | Return a FuncFormatter that maps self.values elements back to |
| 1634 | the original value as a string. Useful with plt.colorbar. |
| 1635 | |
| 1636 | Examples |
| 1637 | -------- |
| 1638 | >>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3]) |
| 1639 | >>> aa = _Normalize(a, width=(0, 0.5, 1)) |
| 1640 | >>> aa._lookup |
| 1641 | 0.000000 0.0 |
| 1642 | 0.166667 0.5 |
| 1643 | 0.666667 2.0 |
| 1644 | 1.000000 3.0 |
| 1645 | dtype: float64 |
| 1646 | >>> aa.format(1) |
| 1647 | '3.0' |
| 1648 | """ |
| 1649 | import matplotlib.pyplot as plt |
| 1650 | |
| 1651 | def _func(x: Any, pos: Any | None = None): |
| 1652 | return f"{self._lookup_arr([x])[0]}" |
| 1653 | |
| 1654 | return plt.FuncFormatter(_func) |
| 1655 | |
| 1656 | @property |
| 1657 | def func(self) -> Callable[[Any, Any | None], Any]: |
no outgoing calls