当将两个图表拼接在一起时,我希望将刻度设置为'inout'样式,并使其在两个图表上都能正常显示,但现在第二个图表覆盖了这些刻度线。
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.01, 5.0, 0.01)
s1 = np.sin(2 * np.pi * t)
s2 = np.exp(-t)
ax1 = plt.subplot(211)
plt.plot(t, s1)
plt.tick_params('x', labelbottom=False, direction='inout', length=6)
ax2 = plt.subplot(212, sharex=ax1)
plt.plot(t, s2)
plt.subplots_adjust(hspace=0)
plt.show()
通过调整hspace
,我们可以看到刻度线实际上是在那里的,只是被覆盖住了。
我曾尝试改变刻度线的z-order,但这并未奏效。
plt.tick_params('x', labelbottom=False, direction='inout', length=6, zorder=100)