【问题标题】:matplotlib: Tick labels disappeared after set sharex in subplots [duplicate]matplotlib:在子图中设置sharex后刻度标签消失[重复]
【发布时间】:2018-07-27 08:07:03
【问题描述】:

在子图中使用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) 之类的东西,但它不起作用。

【问题讨论】:

  • 具体来说,this 回答
  • 那个答案对我不起作用,不知道为什么。

标签: python matplotlib visible


【解决方案1】:

您可以使用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()

【讨论】:

    猜你喜欢
    • 2016-10-27
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    • 2018-11-22
    • 2020-08-29
    • 2014-08-05
    相关资源
    最近更新 更多