Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: add dunder method for math operations on Axes Size divider #27938

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

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions 23 lib/mpl_toolkits/axes_grid1/axes_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
Note that this class is nothing more than a simple tuple of two
floats. Take a look at the Divider class to see how these two
values are used.

Once created, the unit classes can be modified by simple arithmetic
operations: addition /subtraction with another unit type or a real number and scaling
(multiplication or division) by a real number.
"""

from numbers import Real
Expand All @@ -17,14 +21,33 @@

class _Base:
def __rmul__(self, other):
return self * other

def __mul__(self, other):
if not isinstance(other, Real):
return NotImplemented

Check warning on line 28 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L28

Added line #L28 was not covered by tests
return Fraction(other, self)

def __div__(self, other):
paquiteau marked this conversation as resolved.
Show resolved Hide resolved
return (1 / other) * self

Check warning on line 32 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L32

Added line #L32 was not covered by tests

def __add__(self, other):
if isinstance(other, _Base):
return Add(self, other)
else:
return Add(self, Fixed(other))

def __neg__(self):
return -1 * self

Check warning on line 41 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L41

Added line #L41 was not covered by tests

def __radd__(self, other):
# other cannot be a _Base instance, because A + B would trigger
# A.__add__(B) first.
return Add(self, Fixed(other))

Check warning on line 46 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L46

Added line #L46 was not covered by tests
timhoffm marked this conversation as resolved.
Show resolved Hide resolved

def __sub__(self, other):
return self + (-other)

Check warning on line 49 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L49

Added line #L49 was not covered by tests

def get_size(self, renderer):
"""
Return two-float tuple with relative and absolute sizes.
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.