为什么我的 xlabel 不显示? (它不会被切断)

Why does my xlabel not show up? (It's not getting cut off)

我正在制作一个情节,但由于某种原因我的 xlabel 没有出现。我不认为它被切断了,因为当我调用 tight_layout 它仍然没有出现。知道是什么导致了这个问题吗?这是用于生成带有一些合成数据的图形的代码。

import matplotlib.pyplot as plt
import numpy as np


fig, ax = plt.subplots(figsize=(8,5))

Months = ['May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct']

P = [220, 120, 50, 24, 54, 72]
T = [7, 12, 18, 24, 14, 5]

ax.bar(np.arange(1.5, len(P)+1.5), P, 0.5, label='Precipitation', color='k');
ax.set_ylabel("Precipitation, mm", fontsize=12)
ax.legend(loc=2, frameon=False, fontsize=12)

ax2 = ax.twinx()
ax2.plot(np.arange(1.75, len(P)+1.75), T, label='Air Temperature');
ax2.set_ylabel(r'Air Temperature, $^{o}$C', fontsize=12)
ax2.legend(loc=1, frameon=False, fontsize=12)
ax2.set_ylim(0,30)

plt.xticks(np.arange(1.75, len(P)+1.75), Months)
plt.xlim(1, 7.5)
plt.xlabel("2013", fontsize=12)

plt.tight_layout()

以及人物本身的图像(没有 xlabel)。

使用

ax.set_xlabel("2013", fontsize=12)`

而不是

plt.xlabel("2013", fontsize=12)

适合我。