8000 Slightly tighten the Bbox/Transform API. · matplotlib/matplotlib@db9df82 · GitHub
[go: up one dir, main page]

Skip to content

Commit db9df82

Browse files
committed
Slightly tighten the Bbox/Transform API.
At least it's explicit that Bbox.inverse_transformed() follows the Bbox.transformed() semantics, not those of Transform.transform_bbox() or of TransformedBbox (sounds obvious, but you never know...).
1 parent ba7a162 commit db9df82

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ instead.
1212
~~~~~~~~~~~~~~~~~~~~~~~~
1313
``backend_wx.DEBUG_MSG`` is deprecated. The wx backends now use regular
1414
logging.
15+
16+
``BboxBase.inverse_transformed``
17+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18+
19+
``.BboxBase.inverse_transformed`` is deprecated (call `.BboxBase.transformed`
20+
on the `~.Transform.inverted()` transform instead).

examples/pyplots/auto_subplots_adjust.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def on_draw(event):
2626
bbox = label.get_window_extent()
2727
# the figure transform goes from relative coords->pixels and we
2828
# want the inverse of that
29-
bboxi = bbox.inverse_transformed(fig.transFigure)
29+
bboxi = bbox.transformed(fig.transFigure.inverted())
3030
bboxes.append(bboxi)
3131

3232
# this is the bbox that bounds all the bboxes, again in relative
@@ -54,8 +54,9 @@ def on_draw(event):
5454
import matplotlib
5555
matplotlib.artist.Artist.get_window_extent
5656
matplotlib.transforms.Bbox
57-
matplotlib.transforms.Bbox.inverse_transformed
57+
matplotlib.transforms.Bbox.transformed
5858
matplotlib.transforms.Bbox.union
59+
matplotlib.transforms.Transform.inverted
5960
matplotlib.figure.Figure.subplots_adjust
6061
matplotlib.figure.SubplotParams
6162
matplotlib.backend_bases.FigureCanvasBase.mpl_connect

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def get_datalim(self, transData):
227227
result = mpath.get_path_collection_extents(
228228
transform.frozen(), paths, self.get_transforms(),
229229
offsets, transOffset.frozen())
230-
return result.inverse_transformed(transData)
230+
return result.transformed(transData.inverted())
231231
if not self._offsetsNone:
232232
# this is for collections that have their paths (shapes)
233233
# in physical, axes-relative, or figure-relative units

lib/matplotlib/table.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ def get_text_bounds(self, renderer):
157157
"""
158158
Return the text bounds as *(x, y, width, height)* in table coordinates.
159159
"""
160-
bbox = self._text.get_window_extent(renderer)
161-
bboxa = bbox.inverse_transformed(self.get_data_transform())
162-
return bboxa.bounds
160+
return (self._text.get_window_extent(renderer)
161+
.transformed(self.get_data_transform().inverted())
162+
.bounds)
163163

164164
def get_required_width(self, renderer):
165165
"""Return the minimal required width for the cell."""
@@ -430,7 +430,7 @@ def _get_grid_bbox(self, renderer):
430430
for (row, col), cell in self._cells.items()
431431
if row >= 0 and col >= 0]
432432
bbox = Bbox.union(boxes)
433-
return bbox.inverse_transformed(self.get_transform())
433+
return bbox.transformed(self.get_transform().inverted())
434434

435435
def contains(self, mouseevent):
436436
# docstring inherited

lib/matplotlib/tests/test_text.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,12 @@ def test_multiline2():
141141
renderer = fig.canvas.get_renderer()
142142

143143
def draw_box(ax, tt):
144-
bb = tt.get_window_extent(renderer)
145-
bbt = bb.inverse_transformed(ax.transAxes)
146144
r = mpatches.Rectangle((0, 0), 1, 1, clip_on=False,
147145
transform=ax.transAxes)
148-
r.set_bounds(bbt.bounds)
146+
r.set_bounds(
147+
tt.get_window_extent(renderer)
148+
.transformed(ax.transAxes.inverted())
149+
.bounds)
149150
ax.add_patch(r)
150151

151152
horal = 'left'

lib/matplotlib/transforms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ def transformed(self, transform):
513513
[pts[0, 0], pts[1, 1]], [pts[1, 0], pts[0, 1]]]))
514514
return Bbox([ll, [lr[0], ul[1]]])
515515

516+
@cbook.deprecated("3.3", alternative="transformed(transform.inverted())")
516517
def inverse_transformed(self, transform):
517518
"""
518519
Construct a `Bbox` by statically transforming this one by the inverse

0 commit comments

Comments
 (0)
0