xpt*_*xpt 6 python plot matplotlib
在 Matplotlib 中绘制表格时如何在图形和表格之间添加间隙?
这是我的代码:
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()
Run Code Online (Sandbox Code Playgroud)
结果如下所示:
即表头以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])
Run Code Online (Sandbox Code Playgroud)