Lui*_*uis 6 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, zorder=1 )
ax2 = ax1.twinx()
ax2.plot( x, x, color='blue', linewidth=10, zorder=-1)
Run Code Online (Sandbox Code Playgroud)
在上图中,我希望蓝线出现在红色图的后面。
zorder使用双轴时如何控制?
我在用:
蟒蛇:3.4.3 + numpy:1.11.0 + matplotlib:1.5.1
这应该工作
ax1.set_zorder(ax2.get_zorder()+1)
ax1.patch.set_visible(False)
Run Code Online (Sandbox Code Playgroud)