有两个轴面板,一个小面板(灰色)在一个大面积内(白色)。
使用以下代码,我希望蓝线位于灰色小轴面板的顶部,因为蓝线设置为高得离谱zorder
。但结果并非如此。
更改小面板补丁的zorder
无效。
如果我将小面板的背景设置为透明(或使其不可见),则蓝线将显示为未阻止,但此解决方案并不令人满意,因为可能存在 IT需要的情况以保持小面板的背景不透明。
或者这样的要求可能无法通过简单的方式实现,如果通过实现,zorder
行仅在同一轴内有意义?
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.
答案 0 :(得分:2)
看起来(如果zorder与你的例子相反)那么" opaque"第一个(较大)轴的白色背景与第二个(较小)轴重叠,因此一种方法是简单地将较大轴的面颜色设置为透明。另外一定要将整个图形的面颜色设置为白色......
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
答案 1 :(得分:2)
我认为我们必须妥协,所以我想出的解决方案是添加第三层轴,这是透明的,它是真正绘制蓝线的那一层。
当然,我们需要进一步微调第一层(ax1
)以抑制冗余元素(例如,默认情况下ax1
也有轴标签和刻度;它们只是隐藏在下面)。
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')