Dan,如果您已经使用 OOP 方式设置了地块
import matplotlib.pyplot as plt
fig, ax_arr = subplots(3, 1, sharex=True)
那么使用类似的东西隐藏 x 轴标签应该很容易
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
# or
plt.setp([a.get_xticklabels() for a in ax_arr[:-1]], visible=False)
但请查看this link,一些更进一步的示例将证明是有用的。
编辑:
如果你不能使用plt.subplots(),我仍然认为你可以使用
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
ax1.plot(x1, y1)
ax2.plot(x2, y2)
plt.setp(ax1.get_xticklabels(), visible=False)
如果你有2个以上的子图,比如
ax1 = fig.add_subplot(N11)
ax2 = fig.add_subplot(N12)
...
axN = fig.add_subplot(N1N)
plt.setp([a.get_xticklabels() for a in (ax1, ..., axN-1)], visible=False)