我在 matplotlib 图的左侧和右侧使用两个 y 轴进行绘图,并使用 zorder
来控制绘图的位置。我需要在同一图中定义 zorder
across 轴。
问题
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
最佳答案
这应该可行
ax1.set_zorder(ax2.get_zorder()+1)
ax1.patch.set_visible(False)
关于python - 使用 2 y 轴时如何定义 zorder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38687887/