Skip to content

Fixes png showing inconsistent inset_axes position #10756

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 2 commits into from
Mar 14, 2018
Merged

Fixes png showing inconsistent inset_axes position #10756

merged 2 commits into from
Mar 14, 2018

Conversation

AlexCav
Copy link
Contributor

@AlexCav AlexCav commented Mar 12, 2018

PR Summary

In response to issue #8120.
Added a fix for inconsistent inset_axes position across different savefig formats.
When creating an inset_axes, not specifying a bbox_transform property will default to parent_axes.transAxes. Changes located in inset_locator.py, with image comparison tests added to test_axes_grid1.py.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak
Copy link
Member

jklymak commented Mar 12, 2018

This looks like a good fix. You have some PEP8 errors (look under the travis py 3.6 tests). Thanks!

@tacaswell tacaswell added this to the v3.0 milestone Mar 12, 2018
@tacaswell
Copy link
Member

Thanks @AlexCav !

@tacaswell
Copy link
Member

(my approval is moudlo the pep8 fixes)

@AlexCav
Copy link
Contributor Author

AlexCav commented Mar 12, 2018

Thank you for the quick approval! I have made the necessary pep8 fixes.

@jklymak jklymak changed the title Fixes png showing inconsistent inset_axes position - Bugfix for issue #8120 Fixes png showing inconsistent inset_axes position Mar 14, 2018
@jklymak jklymak merged commit 4d6632e into matplotlib:master Mar 14, 2018
@AlexCav AlexCav deleted the iss-8120-bugfix branch March 17, 2018 18:11
@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commented Apr 1, 2018

I fear this "fix" has broken the usual behaviour of the inset axes.

Running the following in a jupyter notebook (using matplotlib 2.2.0.post665.dev0+g00ae375cd)

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
xdata, ydata = np.arange(8), np.arange(8)

plt.figure(figsize=(6,3))
ax = plt.subplot(111)
ax.plot(xdata, ydata)
axins = inset_axes(ax, width=0.2, height=0.2, loc='upper left')

results in a huge figure of 18129 x 31028 pixels, which I can't even upload here to show it to you because it's too big. Running that code as script (without the notebook's default bbox_inches="tight") simply results in an empty plot.

The test that has been introduced here,

axins = inset_axes(ax, width=0.2, height=0.2, bbox_to_anchor=(1, 1))

runs fine. However, one cannot , make the bbox_to_anchor to default to anything other than None if the functionality of the loc parameter should be preserved.

I guess one needs to decide which transform should be standard and clearly document that for the other option to specify width and height a different transform needs to be chosen. See also #8952.

@jklymak
Copy link
Member

jklymak commented Apr 1, 2018

I think one proper thing to do here is move inset_axes into the main axes method and overhaul it, including better documentation. This is the one thing from axes_grid1 that I would use somewhat often and it seems like core functionality.

Not to say that a more short term fix to these inconsistencies would also not be welcome.

@jklymak
Copy link
Member

jklymak commented Apr 1, 2018

Btw can this be a new issue so it gets some attention?

@ImportanceOfBeingErnest
Copy link
Member

I simply think that this is not the proper fix for the issue. Shouldn't it be reverted back and the old issue be reopened?

@jklymak
Copy link
Member

jklymak commented Apr 2, 2018

I agree that the fix is wrong, though I think I like the test, so I won't revert.

It seems that #8120 is just bad documentation and not using bbox_to_anchor correctly? It seems that if bbox_to_anchor is not None then the default should indeed be bbox_transform = parent._axes.transAxes if it is not supplied. But if bbox_to_anchor is not supplied, then the transform needs to stay None. #8952 explains things quite well.

It is all a bit confusing, not helped by quadruply nested subclasses. I'll try and have a PR in the next couple of days, if no one beats me to it, that tries to a) fix the error, b) make the documentation more clear, c) add an error check on the bbox argument so that it at least has all the elements needed to make a width and height.

@jklymak
Copy link
Member

jklymak commented Apr 11, 2018

As discussed in #10986 and above, this PR incorrectly assigned transAxes as the transform. While @AlexCav is correct, that will yield the a consistent application of the inset across different DPI output, it breaks old behaviour. So I'm reverting the merge...

@jklymak
Copy link
Member

jklymak commented Apr 11, 2018

OK, can't auto-revert... New PR

tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Aug 5, 2018
Fixes png showing inconsistent inset_axes position
Conflicts:
	lib/mpl_toolkits/axes_grid1/inset_locator.py
          - keep non-superified version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants