#read data into dataframe
con=pd.read_csv(\'testOutput.csv\')
\'\'\'
testOutput.csv looks like :
Sample,Count
sample1,99.9
sample2, 96.6
\'\'\'
## set colours to
In principle, the same strategies than in this question's answer apply here.
bbox
You may freely position the table on your graph using the bbox
argument, bbox = [left, bottom, width, height]
where left, bottom, width, height
are fractions of the axes.
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.DataFrame({"count" : np.sort(np.random.rand(100))*100})
summary=pd.DataFrame(df['count'].describe())
plt.barh(range(len(df)),df["count"])
plt.table(cellText=summary.values,
rowLabels=summary.index,
colLabels=summary.columns,
cellLoc = 'right', rowLoc = 'center',
loc='right', bbox=[.65,.05,.3,.5])
plt.savefig("out.png")
plt.show()
This would also allow to put the table outside the axes by choosing the paramters larger than 1. In order to make space for the table, you can then shrink the subplots, plt.subplots_adjust(right=0.75)
.
plt.table(cellText=summary.values,
rowLabels=summary.index,
colLabels=summary.columns,
cellLoc = 'right', rowLoc = 'center',
loc='right', bbox=[1,.3,.3,.5])
plt.subplots_adjust(right=0.75)
You may use a dedicated subplot to put the table in.
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.DataFrame({"count" : np.sort(np.random.rand(100))*100})
summary=pd.DataFrame(df['count'].describe())
fig,(ax,tabax) = plt.subplots(ncols=2, gridspec_kw=dict(width_ratios=[2,1]))
ax.barh(range(len(df)),df["count"])
tabax.axis("off")
tabax.table(cellText=summary.values,
rowLabels=summary.index,
colLabels=summary.columns,
cellLoc = 'right', rowLoc = 'center',
loc='center')
plt.savefig("out.png")
plt.show()