Skip to content
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

inset locator fix with tests added #24783

Merged
merged 1 commit into from Jan 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/inset_locator.py
Expand Up @@ -73,7 +73,7 @@ def __call__(self, ax, renderer):
bbox = self.get_window_extent(renderer)
px, py = self.get_offset(bbox.width, bbox.height, 0, 0, renderer)
bbox_canvas = Bbox.from_bounds(px, py, bbox.width, bbox.height)
tr = ax.figure.transFigure.inverted()
tr = ax.figure.transSubfigure.inverted()
return TransformedBbox(bbox_canvas, tr)


Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py
Expand Up @@ -716,3 +716,23 @@ def test_removal():
fig.canvas.draw()
col.remove()
fig.canvas.draw()


@image_comparison(['anchored_locator_base_call.png'], style="mpl20")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@image_comparison(['anchored_locator_base_call.png'], style="mpl20")
@image_comparison(['anchored_locator_base_call.png'], style="mpl20", remove_text=True)

Or is the text a crucial part of the appearance?

(It is generally a good idea to remove the text if not needed, plus that it is cropped in this example.)

(A good approach to avoid conflicts is to insert the test at some random location in the file. This is as many insert it at the end and therefore it is more likely that there will be conflicts there. Hopefully this will be merged soon though.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oscargus. Thank you for the feedback. I agree with your comments but i had trouble generating a test image that would pass the image comparison test when remove_text is true. I do agree, however, that the test should be for just the image and not the text. I have resubmitted the test case where I didn't put the "remove_text" but did remove all the text in the test case and generate a test image without any text.

If this isn't quite acceptable, can you provide more details on your proposed approach? Thanks!

def test_anchored_locator_base_call():
fig = plt.figure(figsize=(3, 3))
fig1, fig2 = fig.subfigures(nrows=2, ncols=1)

ax = fig1.subplots()
ax.set(aspect=1, xlim=(-15, 15), ylim=(-20, 5))
ax.set(xticks=[], yticks=[])

Z = cbook.get_sample_data(
"axes_grid/bivariate_normal.npy", np_load=True
)
extent = (-3, 4, -4, 3)

axins = zoomed_inset_axes(ax, zoom=2, loc="upper left")
axins.set(xticks=[], yticks=[])

axins.imshow(Z, extent=extent, origin="lower")