简体   繁体   English

imshow和mark_inset图的分层不正确

[英]Incorrect layering of imshow and mark_inset plots

The following code, used in an interactive matplotlib session, eg ipython --pylab , 以下代码在交互式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)

produces this result 产生这个结果

As you can see, the red inset marker lines are layered over the rightmost inset image. 如您所见,红色插图标记线位于最右边的插图图像上。 I tried reordering the commands and messing around with the zorder parameter, but nothing works. 我尝试重新排序命令并弄乱了zorder参数,但没有任何效果。

How can I fix this? 我怎样才能解决这个问题?

If this is about the red line going on top of the right image, this can indeed be solved with zorder 如果这是关于右图上方的红线,则确实可以使用zorder解决

axins1 = plt.axes([inset_start, .59, inset_width, 0.26])
axins1.set_zorder(5)

在此处输入图片说明

What I find more disturbing is that the image within the axes hides the axes spines, this is a problem to which I don't have any solution. 我发现更令人不安的是,轴内的图像隐藏了轴刺,这是我没有任何解决方案的问题。

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

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