Python 子地块axis.set_zorder,地块不相似

Python 子地块axis.set_zorder,地块不相似,python,matplotlib,subplot,Python,Matplotlib,Subplot,我正在用twinx绘制X个图,我想设置这些轴的zorder: import matplotlib.pyplot as plt import numpy as np from pandas import plotting x1 = np.linspace(1,20,10) y1 = np.random.random_integers(1,20,10) y2 = np.random.random_integers(1,20,10) y3 = np.random.random_integers

我正在用
twinx
绘制X个图,我想设置这些轴的
zorder

import matplotlib.pyplot as plt 
import numpy as np
from pandas import plotting


x1 = np.linspace(1,20,10) 
y1 = np.random.random_integers(1,20,10)
y2 = np.random.random_integers(1,20,10)
y3 = np.random.random_integers(1,20,10)

fig,ax = plt.subplots()
bx = ax.twinx()
cx = ax.twinx()
colors = getattr(getattr(plotting, '_style'), '_get_standard_colors') 
 (num_colors=5)

ax.plot(x1,y1, label = "1",color= colors[0])
bx.plot(x1,y2, label = "2",color= colors[1])
cx.plot(x1,y3, label = "3",color= colors[2])


cx.spines["right"].set_position(("axes", 1.1))


li,la = ax.get_legend_handles_labels()
li2,la2 = bx.get_legend_handles_labels()
li3,la3 = cx.get_legend_handles_labels()

lines= li+li2+li3
labels = la+la2+la3

ax.legend(lines, labels, loc=9, ncol=2, bbox_to_anchor=(0.5, 1.1))

ax.set_zorder(9)
bx.set_zorder(7)
cx.set_zorder(5)

plt.show()
设置
set\u zorder
后,
bx
cx
的绘图消失。没有zorder,一切都很好

谢谢你的帮助:)


您需要使具有较高zorder的轴的背景更透明,否则无法看到较低的绘图

ax.set_facecolor("none")
bx.set_facecolor("none")
此外,您还可以将最低轴的facecolor设置为白色(但这并非绝对必要)

cx.set_facecolor("white")