以下代码,用于交互式matplotlib会话,例如ipython --pylab
,
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
A = np.random.rand(5, 5)
ex = (0, 5, 0, 5)
imshow(A, interpolation='nearest', extent=ex)
ax = gca()
inset_dist = 0.01
inset_width = 0.1
inset_start_right = 0.68
inset_start = inset_start_right - inset_width
def get_ins_start(nr):
return inset_start - nr * (inset_width + inset_dist)
axins1 = axes([inset_start, .59, inset_width, 0.26])
axins2 = axes([get_ins_start(1.), .59, inset_width, 0.26])
mark_inset(ax, axins1, loc1=1, loc2=2, zorder=10)
mark_inset(ax, axins2, loc1=1, loc2=2, color="red", zorder=20)
axins1.set_xlim((4,5))
axins1.set_ylim(1,2)
axins2.set_xlim((3,4))
axins2.set_ylim(1,2)
axins1.imshow(A, interpolation='nearest', zorder=300, extent=ex)
axins2.imshow(A, interpolation='nearest', zorder=400, extent=ex)
产生此结果
如您所见,红色插入标记线分层在最右边的插图图像上。我尝试重新排序命令并使用zorder
参数搞乱,但没有任何作用。
我该如何解决这个问题?