diff options
| author | RemDelaporteMathurin <rdelaportemathurin@gmail.com> | 2023-01-20 10:23:07 -0500 |
|---|---|---|
| committer | RemDelaporteMathurin <rdelaportemathurin@gmail.com> | 2023-01-20 10:23:07 -0500 |
| commit | 32b8caca3c814158dcd26ea0e9782f683e24fc10 (patch) | |
| tree | 22fddb206d17c7e203b866f53f5011ca4b277472 /docs | |
| parent | 34958cb10d536120ac8025b55ced393a02ced890 (diff) | |
| download | pint-32b8caca3c814158dcd26ea0e9782f683e24fc10.tar.gz | |
added example in docs
Diffstat (limited to 'docs')
| -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 |
