# plasma_plots.labels

*module*

Numbers in plot labels and titles, written the way a reader writes them.

>>> format_number(0.57825)
'0.578'
>>> format_number(0.0)
'0'
>>> format_number(1.234e-5)
'1.23×10⁻⁵'

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/labels.py#L1-L1)

## plasma_plots.labels.format_number

*function*

```python
def format_number(value: float, digits: int = 3, *, mathtext: bool = False) -> str
```

Write a number for a label: plain between 0.001 and 10000, else as a power of ten.

**Parameters**

- `value` (`float`) — The number.
- `digits` (`int`) (default: `3`) — Significant digits. Default: 3.
- `mathtext` (`bool`) (default: `False`) — Write a power of ten as mathtext, ``"$2\times10^{19}$"``, which Matplotlib draws and Plotly typesets (see [`plasma_plots.set_math()`][plasma_plots.plotly_backend.set_math]), instead of Unicode. Default: ``False``.

**Returns**

- (`str`) — E.g. ``"0.578"``, ``"12.3"``, ``"1234"``, ``"0"``, ``"1.23×10⁻⁵"``; trailing zeros are dropped.

**Examples**

```pycon
>>> format_number(5.7825e-01)
'0.578'
>>> format_number(2.0e6)
'2×10⁶'
>>> format_number(2.0e19, mathtext=True)
'$2\times10^{19}$'
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/labels.py#L22-L76)
