Skip to content

Shorten the repr of scaling transforms. #20028

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
Apr 20, 2021
Merged
Show file tree
Hide file tree
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
25 changes: 5 additions & 20 deletions lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,8 @@ def test_str_transform():
IdentityTransform(),
IdentityTransform())),
CompositeAffine2D(
Affine2D(
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]),
Affine2D(
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]))),
Affine2D().scale(1.0),
Affine2D().scale(1.0))),
PolarTransform(
PolarAxesSubplot(0.125,0.1;0.775x0.8),
use_rmin=True,
Expand All @@ -537,14 +531,8 @@ def test_str_transform():
TransformedBbox(
Bbox(x0=0.0, y0=0.0, x1=6.283185307179586, y1=1.0),
CompositeAffine2D(
Affine2D(
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]),
Affine2D(
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]))),
Affine2D().scale(1.0),
Affine2D().scale(1.0))),
LockableBbox(
Bbox(x0=0.0, y0=0.0, x1=6.283185307179586, y1=1.0),
[[-- --]
Expand All @@ -555,10 +543,7 @@ def test_str_transform():
BboxTransformTo(
TransformedBbox(
Bbox(x0=0.0, y0=0.0, x1=8.0, y1=6.0),
Affine2D(
[[80. 0. 0.]
[ 0. 80. 0.]
[ 0. 0. 1.]])))))))"""
Affine2D().scale(80.0)))))))"""


def test_transform_single_point():
Expand Down
9 changes: 8 additions & 1 deletion lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,14 @@ def __init__(self, matrix=None, **kwargs):
self._mtx = matrix.copy()
self._invalid = 0

__str__ = _make_str_method("_mtx")
_base_str = _make_str_method("_mtx")

def __str__(self):
return (self._base_str()
if (self._mtx != np.diag(np.diag(self._mtx))).any()
else f"Affine2D().scale({self._mtx[0, 0]}, {self._mtx[1, 1]})"
if self._mtx[0, 0] != self._mtx[1, 1]
else f"Affine2D().scale({self._mtx[0, 0]})")

@staticmethod
def from_values(a, b, c, d, e, f):
Expand Down