在同一行上为子图设置通用xlabel

时间:2017-02-23 10:11:34

标签: matplotlib label subplot

我看了一下网站上的几个讨论,我无法找到我想要的东西。我想在同一行上将一个共同的xlabel设置为2个子图,如下所示:

enter image description here

我尝试了set_xlabel(),text(),但是第一次它没有工作,而第二次我不能把文本放在底部中心。

如果有人知道如何,我想优化代码。

我的代码:

plt.subplot(121)
plt.barh(range(1, len(y)+1), y)
plt.yticks([i+1.5 for i in range(7)], range(7))
plt.xlim(0, xmax)

plt.ylabel("Y label")

plt.subplot(122)
plt.barh(range(1, len(y2)+1), y2, color="r")
plt.yticks([i+1.5 for i in range(7)], range(7))
plt.xlim(0, xmax)

0 个答案:

没有答案
相关问题