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

Better repr for Bboxes. #3419

Merged
merged 3 commits into from Sep 9, 2014
Merged

Better repr for Bboxes. #3419

merged 3 commits into from Sep 9, 2014

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Aug 27, 2014

Bboxes have fairly ugly reprs right now, this small patch tries to improve that.

Before:

$ python -c 'from matplotlib.transforms import Bbox; print(Bbox([[0, 0], [1, 1]]))'
Bbox('array([[ 0.,  0.],\n       [ 1.,  1.]])')

After:

$ python -c 'from matplotlib.transforms import Bbox; print(Bbox([[0, 0], [1, 1]]))'
Bbox(x0=0.0, x1=1.0, y0=0.0, y1=1.0)

@tacaswell tacaswell added this to the v1.5.x milestone Aug 27, 2014
@tacaswell
Copy link
Member

I am ambivalent to negative on this, as __repr__ is supposed to be able to recreate the object (https://docs.python.org/2/reference/datamodel.html#object.__repr__).

I would leave __repr__ as it is and put that code in __str__ (https://docs.python.org/2/reference/datamodel.html#object.__str__).

@anntzer
Copy link
Contributor Author

anntzer commented Aug 27, 2014

Note that the current repr doesn't satisfy this requirement either (which was one of the reasons I bothered trying to fix this)...
Would Bbox([[0, 0], [1, 1]]) both as str and as repr work for you?

@tacaswell
Copy link
Member

Yes, that would be good.

@pelson
Copy link
Member

pelson commented Aug 27, 2014

I agree with @tacaswell about the repr. My complaint with BBox generally is that I always get confused with the [x0, y0], [x1, y1] vs [x0, x1], [y0, y1] situation. For that reason, I'd be inclined to include your __str__ as well - this is especially useful when you have something like Bbox([[0, 1], [2, 3]]) where the x1 really could be the y0...

@pelson
Copy link
Member

pelson commented Aug 27, 2014

P.S. This would be an easy thing to write a test for... 😉

@anntzer
Copy link
Contributor Author

anntzer commented Aug 27, 2014

Let's add __format__ (which just passes the format string to each coordinate) too.

tacaswell added a commit that referenced this pull request Sep 9, 2014
ENH : Better repr for Bboxes.
@tacaswell tacaswell merged commit 184285d into matplotlib:master Sep 9, 2014
@anntzer anntzer deleted the bbox-repr branch September 11, 2014 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants