Skip to content

Commit

Permalink
Merge pull request #1819 from ksunden/mpl_units_array
Browse files Browse the repository at this point in the history
Short circuit for pint arrays
  • Loading branch information
hgrecco authored Jul 17, 2023
2 parents 2d649ea + 2be029f commit 4cca8ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Pint Changelog
(PR #1805)
- Documented to_preferred and created added an autoautoconvert_to_preferred registry option.
(PR #1803)
- Optimize matplotlib unit conversion for Quantity arrays
(PR #1819)


0.22 (2023-05-25)
Expand Down
3 changes: 3 additions & 0 deletions pint/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def __init__(self, registry):

def convert(self, value, unit, axis):
"""Convert :`Quantity` instances for matplotlib to use."""
# Short circuit for arrays
if hasattr(value, "units"):
return value.to(unit).magnitude
if iterable(value):
return [self._convert_value(v, unit, axis) for v in value]

Expand Down

0 comments on commit 4cca8ab

Please sign in to comment.