MCPcopy
hub / github.com/pydata/xarray / format

Method format

xarray/plot/utils.py:1631–1654  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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]:

Callers 14

_get_units_from_attrsFunction · 0.45
label_from_attrsFunction · 0.45
_nicetitleFunction · 0.45
coerce_nc3_dtypeFunction · 0.45
test_format_scalarFunction · 0.45
test_format_broadcastFunction · 0.45
renderFunction · 0.45
_render_classbodyFunction · 0.45
__post_init__Method · 0.45

Calls

no outgoing calls

Tested by 3

test_format_scalarFunction · 0.36
test_format_broadcastFunction · 0.36