8000 Merge pull request #13110 from anntzer/inverse_transformed · matplotlib/matplotlib@b9dfc53 · GitHub
[go: up one dir, main page]

Skip to content

Commit b9dfc53

Browse files
authored
Merge pull request #13110 from anntzer/inverse_transformed
Slightly tighten the Bbox/Transform API.
2 parents b01325c + 39c9ac9 commit b9dfc53

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
@@ -409,3 +409,9 @@ The *add_all* parameter of `.axes_grid1.axes_grid.Grid`,
409409
`.axes_grid1.axes_grid.ImageGrid`, `.axes_grid1.axes_rgb.make_rgb_axes` and
410410
`.axes_grid1.axes_rgb.RGBAxes` is deprecated. Axes are now always added to the
411411
parent figure, though they can be later removed with ``ax.remove()``.
412+
413+
``BboxBase.inverse_transformed``
414+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
415+
416+
``.BboxBase.inverse_transformed`` is deprecated (call `.BboxBase.transformed`
417+
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.get_affine(), paths, self.get_transforms(),
229229
offsets, transOffset.get_affine().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."""
@@ -431,7 +431,7 @@ def _get_grid_bbox(self, renderer):
431431
for (row, col), cell in self._cells.items()
432432
if row >= 0 and col >= 0]
433433
bbox = Bbox.union(boxes)
434-
return bbox.inverse_transformed(self.get_transform())
434+
return bbox.transformed(self.get_transform().inverted())
435435

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

lib/matplotlib/tests/test_text.py

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

145145
def draw_box(ax, tt):
146-
bb = tt.get_window_extent(renderer)
147-
bbt = bb.inverse_transformed(ax.transAxes)
148146
r = mpatches.Rectangle((0, 0), 1, 1, clip_on=False,
149147
transform=ax.transAxes)
150-
r.set_bounds(bbt.bounds)
148+
r.set_bounds(
149+
tt.get_window_extent(renderer)
150+
.transformed(ax.transAxes.inverted())
151+
.bounds)
151152
ax.add_patch(r)
152153

153154
horal = 'left'

lib/matplotlib/transforms.py

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

476+
@cbook.deprecated("3.3", alternative="transformed(transform.inverted())")
476477
def inverse_transformed(self, transform):
477478
"""
478479
Construct a `Bbox` by statically transforming this one by the inverse

0 commit comments

Comments
 (0)
0