Skip to content

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

Closed

Description

@sorenrasmussen

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

Activity

  1. changed the title [-]Inconsistent inset_axes position between show(), savefig(format='[/-] [+]Inconsistent inset_axes position between show(), savefig(format='png') and savefig(format='pdf')[/+] on Feb 21, 2017
  2. sorenrasmussen commented on Feb 21, 2017

    @sorenrasmussen
    Author

    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.

  3. added this to the milestone on Feb 21, 2017
  4. added
    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    on Feb 21, 2017
  5. tacaswell commented on Feb 21, 2017

    @tacaswell
    Member

    Setting the figure dpi to 300 should also work.

    There is a dpi dependence in there someplace...

  6. sorenrasmussen commented on Feb 21, 2017

    @sorenrasmussen
    Author

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

  7. modified the milestones: , on Sep 24, 2017
  8. tacaswell commented on Sep 24, 2017

    @tacaswell
    Member

    attn @jklymak as another case of pdf / dpi issues

  9. jklymak commented on Sep 24, 2017

    @jklymak
    Member

    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!

  10. modified the milestones: , on Oct 9, 2017
  11. modified the milestones: , on Mar 12, 2018
  12. ImportanceOfBeingErnest commented on Apr 17, 2018

    @ImportanceOfBeingErnest
    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.

  13. modified the milestones: v3.0, v3.1 on Aug 11, 2018
  14. jklymak commented on Feb 12, 2019

    @jklymak
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesbackend: pdftopic: mpl_toolkit

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions