简体   繁体   English

如何在父坐标轴的角添加等宽内嵌坐标轴

[英]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.但是,我需要插入轴iax的纵横比为 1。 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.我知道我可以乱用 inset_axes 位置参数,但理想情况下我想要一些适用于任何给定轴尺寸的方法。

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()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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