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

Skip to content

Commit b186809

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 db06a34 commit b186809

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
`.BboxBase.inverse_transformed` is deprecated (call `.BboxBase.transformed` on
5+
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
@@ -199,7 +199,7 @@ def get_datalim(self, transData):
199199
result = mpath.get_path_collection_extents(
200200
transform.frozen(), paths, self.get_transforms(),
201201
offsets, transOffset.frozen())
202-
result = result.inverse_transformed(transData)
202+
result = result.transformed(transData.inverted())
203203
else:
204204
result = transforms.Bbox.null()
205205
return result

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."""
@@ -433,7 +433,7 @@ def _get_grid_bbox(self, renderer):
433433
for (row, col), cell in self._cells.items()
434434
if row >= 0 and col >= 0]
435435
bbox = Bbox.union(boxes)
436-
return bbox.inverse_transformed(self.get_transform())
436+
return bbox.transformed(self.get_transform().inverted())
437437

438438
def contains(self, mouseevent):
439439
# docstring inherited

lib/matplotlib/tests/test_text.py

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

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

150151
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.2", 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