简体   繁体   中英

Incorrect layering of imshow and mark_inset plots

The following code, used in an interactive matplotlib session, eg 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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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