pandas绘图中xlabel和ylabel不可见

3 投票
1 回答
8193 浏览
提问于 2025-04-18 05:37

如何让下面这个图的横轴标签和纵轴标签变得可见呢?

import pandas as pd
import matplotlib.pyplot as plt
a = {'Test1': {1: 21867186, 4: 20145576, 10: 18018537},
'Test2': {1: 23256313, 4: 21668216, 10: 19795367}}

d = pd.DataFrame(a).T
#print d

f = plt.figure()
plt.xlabel("xTEST")
plt.ylabel("yTEST")

plt.ticklabel_format(style = 'plain')

plt.title('Title here!', color='black')
d.plot(kind='bar', ax=f.gca())
plt.show()

1 个回答

8

当我运行你的例子时,图上的横轴标签(xlabel)和纵轴标签(ylabel)是有显示的,只是根据窗口大小的不同,可能会稍微超出显示范围。

你可以试着加上这一行:

plt.subplots_adjust(bottom=.25, left=.25)

或者直接拉伸一下显示窗口。

撰写回答