diff options
Diffstat (limited to 'docs/user')
| -rw-r--r-- | docs/user/plotting.rst | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/user/plotting.rst b/docs/user/plotting.rst index a008d45..3c3fc39 100644 --- a/docs/user/plotting.rst +++ b/docs/user/plotting.rst @@ -70,6 +70,31 @@ This also allows controlling the actual plotting units for the x and y axes: ax.axhline(26400 * ureg.feet, color='tab:red') ax.axvline(120 * ureg.minutes, color='tab:green') +Users have the possibility to change the format of the units on the plot: + +.. plot:: + :include-source: true + + import matplotlib.pyplot as plt + import numpy as np + import pint + + ureg = pint.UnitRegistry() + ureg.setup_matplotlib(True) + + ureg.mpl_formatter = "{:~P}" + + y = np.linspace(0, 30) * ureg.miles + x = np.linspace(0, 5) * ureg.hours + + fig, ax = plt.subplots() + ax.yaxis.set_units(ureg.inches) + ax.xaxis.set_units(ureg.seconds) + + ax.plot(x, y, 'tab:blue') + ax.axhline(26400 * ureg.feet, color='tab:red') + ax.axvline(120 * ureg.minutes, color='tab:green') + For more information, visit the Matplotlib_ home page. .. _Matplotlib: https://matplotlib.org |
