在Matplotlib中绘制表格时,如何在图表和表格之间添加间隙?

这是my code:

import pandas as pd
import matplotlib.pyplot as plt

dc = pd.DataFrame({'A' : [1, 2, 3, 4],'B' : [4, 3, 2, 1],'C' : [3, 4, 2, 2]})

plt.plot(dc)
plt.legend(dc.columns)
dcsummary = pd.DataFrame([dc.mean(), dc.sum()],index=['Mean','Total'])

plt.table(cellText=dcsummary.values,colWidths = [0.25]*len(dc.columns),
        rowLabels=dcsummary.index,
        colLabels=dcsummary.columns,
        cellLoc = 'center', rowLoc = 'center',
        loc='bottom')
# loc='top'
fig = plt.gcf()

plt.show()

结果看起来像这样:

python - Matplotlib表图,如何在图形和表之间添加间隙-LMLPHP

也就是说,表格标题是使用x-labels的方式。
如何在图表和表格之间添加间隙?谢谢

最佳答案

您应该使用bbox参数:

plt.table(cellText=dcsummary.values,colWidths = [0.25]*len(dc.columns),
rowLabels=dcsummary.index,
colLabels=dcsummary.columns,
cellLoc = 'center', rowLoc = 'center',
loc='bottom', bbox=[0.25, -0.5, 0.5, 0.3])

关于python - Matplotlib表图,如何在图形和表之间添加间隙,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34320946/

10-11 06:19