unxts.interop.matplotlib#
unxts.interop.matplotlib is the canonical location for matplotlib integration. Importing the package — or unxt itself, which imports it automatically when installed — registers a matplotlib.units.ConversionInterface for AbstractQuantity, so unxt.Quantity objects (and the other quantity types) can be plotted directly.
Install#
The recommended install adds unxts.interop.matplotlib alongside unxt via the interop-mpl extra, so it, unxt, and matplotlib are resolved together as a compatible set:
uv add "unxt[interop-mpl]"
pip install "unxt[interop-mpl]"
Or install the package directly:
uv add unxts.interop.matplotlib
pip install unxts.interop.matplotlib
At a glance#
Once installed, plot Quantity objects directly with matplotlib:
import matplotlib.pyplot as plt
import jax.numpy as jnp
import unxt as u
x = u.Q(jnp.linspace(0, 360, 100), "deg")
y = u.Q(jnp.sin(x.ustrip("rad")), "")
fig, ax = plt.subplots()
ax.plot(x, y)
Pages#
Tutorial
Plot data that knows its units — start here: plot two quantities, watch the axis labels write themselves, and see a dataset in the wrong unit land in the right place.
How-to
How to plot quantities with matplotlib — plotting directly, keeping units through the computation with
quaxed, and turning the converter off.
Reference
API — the converter and its setup function.