2015-12-16 56 views
1

如何在Matplotlib中绘制表格时添加图表和表格之间的差距?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() 

,结果是这样的:

plt.table

即,表头是在X-标签的方式。
如何添加图表和表格之间的差距?由于

回答

2

你应该使用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]) 
+0

例如,你可以使用这个位置:'BBOX = [0.1,-0.3,0.9,0.2]' –

+0

好极了!请给我一个参考,我也可以找到'bbox'文档(或者说明它们是什么以及它们为什么以这种方式工作)。谢谢 – xpt

+0

@xpt有很多关于它的信息[http://matplotlib.org/](http://matplotlib.org/api/text_api.html?highlight=bbox#matplotlib.text.Text.set_bbox) –