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

Conversation

matt256
Copy link
Contributor

@matt256 matt256 commented Dec 20, 2022

PR Summary

Addresses the bug report #24589

From report:

When using inset_locator functions in subfigures, the plots are not placed correctly. Adapting this demo
https://matplotlib.org/stable/gallery/axes_grid1/demo_colorbar_of_inset_axes.html
to use subfigures shows incorrect plots.

Implemented the proposed resolution and wrote a unit test that validates the image referenced in the bug report is generated properly

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@@ -707,3 +707,36 @@ 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!

@matt256 matt256 force-pushed the PR_inset_locator branch 2 times, most recently from 6ec5b75 to 0e801e0 Compare December 22, 2022 12:20
added remove_text to image comparison decorator

Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>

removed inaccurate comments

Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>

removed text from test image and test

Update lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py

changed subfigure generation to default

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>

got rid of colorbar

removed colorbar and changed test image
@matt256
Copy link
Contributor Author

matt256 commented Dec 23, 2022

In the most recent commit, I removed the colorbar because it wasn't relevant to the test or the issue that this patch is meant to solve. Without the colorbar, the issue still presents itself before the fix and is resolved after it, regardless of the colorbar.

@matt256
Copy link
Contributor Author

matt256 commented Jan 1, 2023

@QuLogic , @oscargus just wanted to follow up on this thread. Were there any other comments that still needed to be addressed?

@QuLogic QuLogic added this to the v3.6.3 milestone Jan 10, 2023
Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

Looks good to me - thanks a lot, especially as this looks like your first PR to Matplotlib!

@lumberbot-app
Copy link

lumberbot-app bot commented Jan 10, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.6.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 d3cf4291e4a23d7bde39fba96d82cc1416351836
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #24783: inset locator fix with tests added'
  1. Push to a named branch:
git push YOURFORK v3.6.x:auto-backport-of-pr-24783-on-v3.6.x
  1. Create a PR against branch v3.6.x, I would have named this PR:

"Backport PR #24783 on branch v3.6.x (inset locator fix with tests added)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

dstansby added a commit to dstansby/matplotlib that referenced this pull request Jan 10, 2023
dstansby added a commit that referenced this pull request Jan 10, 2023
…783-on-v3.7.x

Backport PR #24783 on branch v3.7.x (inset locator fix with tests added)
timhoffm added a commit that referenced this pull request Jan 10, 2023
…v3.6.x

"Backport PR #24783 on branch v3.6.x (inset locator fix with tests added)"
@ksunden ksunden mentioned this pull request Feb 20, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

[Bug]: inset_locator is broken when used with subfigures
4 participants