Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add support for plotting brainunit.Quantity instances in matplotlib #54

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion brainunit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from ._unit_constants import __all__ as _constants_all
from ._unit_shortcuts import *
from ._unit_shortcuts import __all__ as _std_units_all
from ._matplotlib_compat import *
from ._matplotlib_compat import __all__ as _matplotlib_compat

__all__ = ['math'] + _common_all + _std_units_all + _constants_all + _base_all + _celsius_all
del _common_all, _std_units_all, _constants_all, _base_all, _celsius_all
del _common_all, _std_units_all, _constants_all, _base_all, _celsius_all, _matplotlib_compat
18 changes: 18 additions & 0 deletions brainunit/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,24 @@ def unit(self, *args):
"Please create a new Quantity object with the unit you want."
)

def to(self, new_unit: Unit) -> 'Quantity':
"""
Convert the given :py:class:`Quantity` into the given unit.

Examples::

>>> a = jax.numpy.array([1, 2, 3]) * mV
>>> a.to(volt)
array([0.001, 0.002, 0.003]) * volt

Args:
new_unit: The new unit to convert the quantity to.

Returns:
The new quantity with the given unit.
"""
return self.in_unit(new_unit)

def to_decimal(self, unit: Unit = UNITLESS) -> jax.typing.ArrayLike:
"""
Convert the given :py:class:`Quantity` into the decimal number.
Expand Down
Loading