我想绘制一条曲线和缩放,并有一个插图,显示我的绘图的特定部分的缩放。这是我的代码,部分实现了这一点:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
fig, ax = plt.subplots()
axins = inset_axes(ax, 1,1 , loc=2, bbox_to_anchor=(.08, 0.35),bbox_transform=axfft.figure.transFigure)
x = np.linspace(0, 3, 100)
y = x**2
ax.plot(x, y)
axins.plot(x, y)
x1, x2, y1, y2 = 1, 2, .5, 4.5 # specify the limits
axins.set_xlim(x1, x2) # apply the x-limits
axins.set_ylim(y1, y2) # apply the y-limits
plt.xticks(visible=False)
plt.yticks(visible=False)
mark_inset(ax, axins, loc1=2, loc2=3, fc="none", ec="0.5")
这是它产生的输出:
我的问题:
如何使mark_inset
将线条放在插图的右角而不是左角?目前的情况是,指示线穿过我的插图,我不想这样。在
mark_inset
始终在插入和位置矩形上使用相同的角点。您可以用loc1
和loc2
参数设置这些参数。在为防止线与轴交叉,可以使用
相关问题 更多 >
编程相关推荐