Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib table plot, how to add gap between the graph and table

How to add gap between the graph and table when plotting table in Matplotlib?

This is 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()

and the result looks like this:

plt.table

I.e., the table header is in the way of x-labels.
How to add gap between the graph and table? Thanks

like image 332
xpt Avatar asked Dec 16 '15 19:12

xpt


1 Answers

You should use bbox argument:

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])
like image 60
Vasya Pravdin Avatar answered Oct 05 '22 09:10

Vasya Pravdin