Skip to content

Inconsistent inset_axes position between show(), savefig(format='png') and savefig(format='pdf') #8120

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

Closed
sorenrasmussen opened this issue Feb 21, 2017 · 7 comments
Labels
backend: pdf Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues topic: mpl_toolkit
Milestone

Comments

@sorenrasmussen
Copy link

sorenrasmussen commented Feb 21, 2017

Bug report

Bug summary

inset_axes inconsistently positioned between show(), savefig(...,format='png') and savefig(...format='pdf') when the dpi option is set.

Code for reproduction

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes

fig = plt.figure(dpi=150);

ax1 = plt.gca()
ax1ins1 = inset_axes(ax1, width=.7, height=.7,bbox_to_anchor=(100,100))

plt.savefig("test.pdf",format='pdf',dpi=300,bbox_inches="tight")
plt.savefig("test.png",format='png',dpi=300,bbox_inches="tight")
plt.show()

Actual outcome

PDF:
test_pdf
PNG:
test
show():
show

Expected outcome

I would expect all the results to come out the same.

Matplotlib version

  • Matplotlib 2.0.0 (conda)
  • Python 2.7.13 (conda)
  • Platform: Linux
@sorenrasmussen sorenrasmussen changed the title Inconsistent inset_axes position between show(), savefig(format=' Inconsistent inset_axes position between show(), savefig(format='png') and savefig(format='pdf') Feb 21, 2017
@sorenrasmussen
Copy link
Author

sorenrasmussen commented Feb 21, 2017

Note:
Setting bbox_transform=ax1.figure.transFigure for the inset_axes makes the positioning consistent. However, I would still expect it to be consistent without doing so.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Feb 21, 2017
@tacaswell tacaswell added the Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues label Feb 21, 2017
@tacaswell
Copy link
Member

Setting the figure dpi to 300 should also work.

There is a dpi dependence in there someplace...

@sorenrasmussen
Copy link
Author

Setting the figure DPI to 300 makes the PNG look right, but not the PDF.

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.1.1 (next bug fix release) Sep 24, 2017
@tacaswell
Copy link
Member

attn @jklymak as another case of pdf / dpi issues

@jklymak
Copy link
Member

jklymak commented Sep 24, 2017

Yes. I think it's easy to fix (in general I think the rendered width should just return 72 times the inches width so it's in pdfs dpi units like the other backends. But terrifying to then fix all the workarounds that have been added here and there!

@tacaswell tacaswell modified the milestones: 2.1.1 (next bug fix release), 2.2 (next feature release) Oct 9, 2017
@tacaswell tacaswell modified the milestones: needs sorting, v3.0 Mar 12, 2018
@ImportanceOfBeingErnest
Copy link
Member

I updated the documentation of inset_axes in #11060. Among other things it now includes the sentence

Note that the units of the bounding box are determined through the
transform in use. When using bbox_to_anchor it almost always makes
sense to also specify a bbox_transform. This might often be the axes
transform parent_axes.transAxes.

There are also several examples added. The code does not forbid to specify a bounding box in pixels and use the default transform=None (i.e. the display coordinates), as this may still be useful in some limited cases. However I hope that the docs and examples are now clear enough such that people will not try to position something in pixel coordinates and then wonder why there is some dpi dependence introduced.

@tacaswell tacaswell modified the milestones: v3.0, v3.1 Aug 11, 2018
@jklymak
Copy link
Member

jklymak commented Feb 12, 2019

I think this has substantively been fixed by the doc changes...

@jklymak jklymak closed this as completed Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: pdf Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues topic: mpl_toolkit
Projects
None yet
Development

No branches or pull requests

5 participants