4
votes

There are two axes panels, with a small one (in gray color) inside a big one (white color).

With the following code, I am expecting the blue line to be on top of the gray small axes panel, because the blue line is set to have a ridiculously high zorder. But it turns out not to be the case.

Changing the zorder of the patch of the small panel has no effect.

If I set the background of the small panel to be transparent (or make it invisible), then the blue line will appear unblocked, but this solution is not satisfactory, because there may be situations in which IT IS REQUIRED to keep the background of the small panel to be opaque.

Or maybe such a requirement is not achievable in a simple way, if by implementation the zorder of lines are only meaningful within the same axes?

f = figure()

ax1 = f.add_axes([0.1,0.1,0.8,0.8], zorder=1)
ax2 = f.add_axes([0.3,0.2,0.5,0.4], zorder=2)
ax2.patch.set_facecolor('gray')
ax2.patch.set_zorder(-9999999)
ax1.plot([0,1], [0,1], zorder=99999999, color='blue')
ax2.plot([0,1], [0,3], zorder=-99999, color='red')

# New Edit:
# To make the problem more to the point, what if someone
# also wants the background of the big panel to be green
# (with the following command)?  See the second figure.
ax1.patch.set_facecolor('green')
# This seems to mean that the small panel really has to
# somehow "insert" into the z-space between the big panel
# and the blue line.

Figure generated by the following code New image

2

2 Answers

2
votes

It would appear that (if the zorder is reversed from your example) then the "opaque" white background from your first (larger) axes is overlapping the second (smaller) axes, so one way is to simply set the face color of the larger axes to transparent. Also be sure to set the face color of the entire figure to white...

f.set_facecolor('white')

ax2 = f.add_axes([0.3,0.2,0.5,0.4], zorder=1)
ax2.patch.set_facecolor('gray')
ax2.plot([0,1], [0,3], color='red')

ax1 = f.add_axes([0.1,0.1,0.8,0.8], zorder=2)
ax1.plot([0,1], [0,1], color='blue')
ax1.patch.set_alpha(0.0)#make background transparent

enter image description here

2
votes

I think we just have to compromise, so the solution I come up with is to add a third layer of axes, which is transparent and it is the one who really draws the blue line.

Of course, we need to further fine-tune the first layer (ax1) a bit to suppress redundant elements (for example, by default ax1 also has axes labels and ticks; they are just hidden below).

f = figure()

ax1 = f.add_axes([0.1,0.1,0.8,0.8], zorder=0)
ax1.patch.set_facecolor('green')

ax2 = f.add_axes([0.3,0.2,0.5,0.4], zorder=1)
ax2.patch.set_facecolor('gray')

ax2.plot([0,1], [0,3], color='red')

ax3 = f.add_axes([0.1,0.1,0.8,0.8], zorder=2)
ax3.patch.set_alpha(0)
ax3.plot([0,1], [0,1], color='blue')

enter image description here