Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

inset_locator.inset_axes produces axes without extent and at incorrect position. #8952

Copy link
Copy link
Closed
@ImportanceOfBeingErnest

Description

The mpl_toolkits.axes_grid1.inset_locator.inset_axes is not working as expected when using the bbox_to_anchor argument. Using inset_axes(ax, width="70%", height="30%",bbox_to_anchor=(0.4,0.1), loc=3) gives an inset axes without extention at an incorrect position. (This issue is raised in this stackoverflow post.)

Complete example:

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
plt.rcParams["figure.figsize"] = 4,3

fig, ax= plt.subplots()

iax =inset_axes(ax, width="70%", height="30%", bbox_to_anchor=(0.4,0.1), loc=3)

iax.plot([1,2,4])
plt.show()

gives

image

and a warning

c:\winpython\winpython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axis.py:1035: UserWarning: Unable to find pixel distance along axis for interval padding of ticks; assuming no interval padding needed.

when being run with python 2.7, matplotlib 2.0.2. In the lower left corner of the image you see what I suppose are the ticks of the zero-sized axes. Since the documentation clearly states that width and height can be strings (and they actually can be if bbox_to_anchor is ommited) and since the default bbox_transform is parent_axes.transAxes, the above is clearly expected to work.

Note that when explicitely supplying the bbox_transform we at least get the axes at the correct position,

iax =inset_axes(ax, width="70%", height="30%", bbox_to_anchor=(0.4,0.1), 
                         loc=3, bbox_transform=ax.transAxes)

image

while width and height are further ignored.

Is this an error in the documentation or a bug in the matplotlib code?

The expected outcome of the above would be an inset axes with the lower left corner at (0.4,0.1) in axes coordinates and a width of 0.3 and a height of 0.7 (also in normalized axes units) as shown in the below image (which is produced by other means than inset_axes):

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.