简体   繁体   English

为什么我的xlabel没有出现? (它没有被切断)

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

I'm making a plot and for some reason my xlabel is not showing up. 我正在制作一个情节,由于某种原因我的xlabel没有出现。 I don't think it is getting cut off, because when I call tight_layout it still doesn't show up. 我不认为它会被切断,因为当我打电话给tight_layout它仍然没有显示出来。 Any idea what is causing this issue? 知道是什么导致了这个问题吗? Here is the code used to generate the figure with some made up data. 这是用于生成具有一些组成数据的图的代码。

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()

And an image of the figure itself (With the xlabel not present). 和图形本身的图像(没有x标签)。

在此输入图像描述

Using 运用

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

instead of 代替

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

works for me. 适合我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM