我的 matplotlib 有一个问题,它生成的绘图与标题相去甚远。我的代码是:
df = pandas.read_csv(csvpath, delimiter=',',
index_col=0,
parse_dates=[0], dayfirst=True,
names=['Date','test1'])
df.plot(subplots=True, marker='.',markersize=8, title ="test", fontsize = 10, color=['b','g','g'], figsize=(8, 22))
imagepath = 'capture.png'
plt.savefig(imagepath)
生成的图形示例是:
知道为什么会这样吗?非常感谢。
最佳答案
您可以通过从 df.plot返回的数组中的 3 个
。使用 axis
对象之一获取 figure
对象来调整标题位置fig.tight_layout
会删除多余的空格,但一个已知的问题是它还会在顶部绘图中设置图形标题。但是,您可以使用下面的最后一行来解决这个问题。
ax = df.plot(subplots=True, marker='.', markersize=8,
title ="test", fontsize = 10, color=['b','g','g'],
figsize=(8, 22))[0]
fig = ax.get_figure()
fig.tight_layout()
fig.subplots_adjust(top=0.95)
关于python - 标题和绘图 matplotlib 之间的巨大空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39331143/