2015-12-16 58 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) –