matplotlib:在子图中设置 sharex 后刻度标签消失

matplotlib: Tick labels disappeared after set sharex in subplots

在子图中使用sharexsharey时,刻度标签会消失,如何恢复? 这是刚刚从 official website:

复制的示例
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)
axs[0, 0].plot(x)

plt.show()

我们将看到:

正如我们所见,右上角的图没有任何刻度标签,而其他图也因为共享轴而缺少一些标签。 我想我应该使用类似 plt.setp(ax.get_xticklabels(), visible=True) 的东西,但它不起作用。

可以使用tick_params()来设计剧情:

f, ax = plt.subplots(2, 2, sharex=True, sharey=True)

for a in f.axes:
    a.tick_params(
    axis='x',           # changes apply to the x-axis
    which='both',       # both major and minor ticks are affected
    bottom=True,
    top=False,
    labelbottom=True)    # labels along the bottom edge are on

plt.show()