简体   繁体   中英

How to add a equal-aspect inset axes in the corner of a parent axes

I want to add an inset axis to the upper left corner of a parent axis. This can easily be done like so:

fig, ax = plt.subplots()
iax = ax.inset_axes([0,.8, .2, .2])

插图轴

However, I need the inset axis iax to have an aspect ratio of one. But when I change the aspect ratio, the inset axis shifts slightly to the right.

iax.set_aspect('equal')

偏移相等纵横比插入轴

How can I make the aspect ratio of the inset axis "equal", while still having it nestled in the upper left corner? I know I could just mess around with the inset_axes location parameter, but ideally I want some method that works for any given axis size.

You need to set the anchor parameter as follows:

from matplotlib import pyplot as plt

fig, ax = plt.subplots()
iax = ax.inset_axes([0, .8, .2, .2])
iax.set_aspect('equal', anchor="NW")
plt.show()

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM