Python 使用2 y轴时如何定义zorder?

Python 使用2 y轴时如何定义zorder?,python,numpy,matplotlib,Python,Numpy,Matplotlib,我使用matplotlib图形左侧和右侧的两个y轴进行绘图,并使用zorder控制绘图的位置。我需要在同一个图中跨轴定义zorder 问题 import numpy as np import matplotlib.pyplot as plt x = np.arange(-10,10,0.01) fig, ax1 = plt.subplots( 1, 1, figsize=(9,3) ) ax1.plot( x, np.sin(x), color='red', linewidth=10, zo

我使用matplotlib图形左侧和右侧的两个y轴进行绘图,并使用
zorder
控制绘图的位置。我需要在同一个图中跨轴定义
zorder


问题

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-10,10,0.01)

fig, ax1 = plt.subplots( 1, 1, figsize=(9,3) )
ax1.plot( x, np.sin(x), color='red', linewidth=10, zorder=1 )
ax2 = ax1.twinx()
ax2.plot( x, x, color='blue', linewidth=10, zorder=-1)

在上一张图中,我希望蓝线出现在红色绘图的后面

使用双轴时如何控制
zorder


我正在使用:


python:3.4.3+numpy:1.11.0+matplotlib:1.5.1

看起来这两个轴有单独的z堆栈。轴按z顺序排列,最新轴位于顶部,因此需要将要位于顶部的曲线移动到创建的最后一个轴:

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-10,10,0.01)

fig, ax1 = plt.subplots( 1, 1, figsize=(9,3) )
ax1.plot( x, x, color='blue', linewidth=10 )
ax2 = ax1.twinx()
ax2.plot( x, np.sin(x), color='red', linewidth=10 )
这应该行得通

ax1.set_zorder(ax2.get_zorder()+1)
ax1.patch.set_visible(False)

好。。。不。如果更改打印顺序,打印顺序将保持不变。在您的代码中,您将
ax1
更改为
ax2
(即左和右),而不是绘图顺序:)谢谢,这就是我的意思;我对回复进行了编辑,使其更加具体