Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Convert units when returning Rect bbox
  • Loading branch information
dstansby committed Dec 3, 2017
commit f40607e20675560d1fe64e1e8f5c7038a4d2b325
18 changes: 13 additions & 5 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,7 @@ def _update_patch_transform(self):
makes it very important to call the accessor method and
not directly access the transformation member variable.
"""
x0 = self.convert_xunits(self._x0)
y0 = self.convert_yunits(self._y0)
x1 = self.convert_xunits(self._x1)
y1 = self.convert_yunits(self._y1)
x0, y0, x1, y1 = self._convert_units()
bbox = transforms.Bbox.from_extents(x0, y0, x1, y1)
rot_trans = transforms.Affine2D()
rot_trans.rotate_deg_around(x0, y0, self.angle)
Expand All @@ -703,6 +700,16 @@ def _update_x1(self):
def _update_y1(self):
self._y1 = self._y0 + self._height

def _convert_units(self):
'''
Convert bounds of the rectangle
'''
x0 = self.convert_xunits(self._x0)
y0 = self.convert_yunits(self._y0)
x1 = self.convert_xunits(self._x1)
y1 = self.convert_yunits(self._y1)
return x0, y0, x1, y1

def get_patch_transform(self):
self._update_patch_transform()
return self._rect_transform
Expand All @@ -720,7 +727,7 @@ def get_xy(self):
return self._x0, self._y0

def get_width(self):
"Return the width of the rectangle"
"Return the width of the rectangle"
return self._width

def get_height(self):
Expand Down Expand Up @@ -797,6 +804,7 @@ def set_bounds(self, *args):
self.stale = True

def get_bbox(self):
x0, y0, x1, y1 = self._convert_units()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this call to convert_units? Am I missing a side effect or was this meant to be passed to the from_extents call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _x0, _y0 etc. coords are now all stored in the class with units attached, so this strips the units because I don't think from_extents takes units.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the next line passes in self._x0 etc not x0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. PR incoming

return transforms.Bbox.from_extents(self._x0, self._y0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to use the unit conversions, as in _update_patch_transform()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it probably does, but no-one every added it originally. I'll add it in another commit.

self._x1, self._y1)

Expand Down