如何增加熊猫数据框图的填充?

时间:2018-11-15 06:25:10

标签: python pandas matplotlib

我正在尝试使用熊猫绘制一些直方图。这是一些示例代码,其功能与我正在执行的操作类似:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
ts = pd.Series(np.random.randn(1000), index=pd.date_range('2018-10-14', periods=1000))
df = pd.DataFrame(np.random.randn(1000, 6), index=ts.index, columns=['A', 'B', 'C', 'D', 'E', 'F'])
df = df.cumsum()
df.hist()

数据以直方图显示,但有一个小问题:

six histograms with a D overlapping -20

我的顶部直方图标签与下一行底部的X轴标签重叠。

我希望能够在这些之间添加一些间距,但是我还没有找到有关如何执行此操作的信息。

如何使用pandas和matplotlib增加绘图之间的填充?

2 个答案:

答案 0 :(得分:2)

您可以在df.hist()通话后使用subplots_adjust

plt.subplots_adjust(hspace=0.5) 

enter image description here

答案 1 :(得分:1)

如joe指定的那样,您可以在代码中指定hspace,而且可以在configure subplots之后单击plt.show()按钮。以这种比例动态修改hspace值。

第1步

enter image description here

第2步

enter image description here

第3步

enter image description here