简体   繁体   English

Matplotlib的inset_locator具有反转轴

[英]Matplotlib's inset_locator with inverted axes

I want to make a standard inset into my plot. 我想在我的情节中制作标准插图。 But I don't get how to use the inset_locator . 但我不知道如何使用inset_locator Here is my code: 这是我的代码:

import matplotlib.pyplot as plt
import numpy as np

from mpl_toolkits.axes_grid1.inset_locator import inset_axes, mark_inset

x = np.linspace(0, 2)
plt.plot(x, np.sin(x))

ax = plt.gca()
ax.invert_yaxis()
axins = inset_axes(ax, width='40%', height='30%', loc='lower left')
x_in = np.linspace(1.25, 1.75)
axins.plot(x_in, np.sin(x_in))
axins.invert_yaxis()
mark_inset(ax, axins, loc1=2, loc2=4)
plt.show()

And the result is: 结果是: 在此输入图像描述

Apparently it the edges connect the wrong corners. 显然它的边缘连接了错误的角落。 How do I get them right, when my axis goes from maximum to minimum? 当我的轴从最大值变为最小值时,如何才能使它们正确?

Unfortunately the mark_inset cannot cope with inverted axes. 不幸的是, mark_inset无法应对反转轴。 So you need to set the locations of the connectors manually. 因此,您需要手动设置连接器的位置。

patch, pp1,pp2 = mark_inset(ax, axins, loc1=1,loc2=1)
pp1.loc1 = 1
pp1.loc2 = 4
pp2.loc1 = 4
pp2.loc2 = 1

在此输入图像描述

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

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