Skip to content

Get correct renderer for axes_grid1 inset axes with bbox_inches=tight #26291

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

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions lib/mpl_toolkits/axes_grid1/inset_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def draw(self, renderer):
raise RuntimeError("No draw method should be called")

def __call__(self, ax, renderer):
if renderer is None:
renderer = ax.figure._get_renderer()
self.axes = ax
bbox = self.get_window_extent(renderer)
px, py = self.get_offset(bbox.width, bbox.height, 0, 0, renderer)
Expand Down
10 changes: 10 additions & 0 deletions lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from itertools import product
import io
import platform

import matplotlib as mpl
Expand Down Expand Up @@ -247,6 +248,15 @@ def test_inset_axes_complete():
bbox_transform=ax.transAxes)


def test_inset_axes_tight():
# gh-26287 found that inset_axes raised with bbox_inches=tight
fig, ax = plt.subplots()
inset_axes(ax, width=1.3, height=0.9)

f = io.BytesIO()
fig.savefig(f, bbox_inches="tight")


@image_comparison(['fill_facecolor.png'], remove_text=True, style='mpl20')
def test_fill_facecolor():
fig, ax = plt.subplots(1, 5)
Expand Down