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.