I need to plot a table in matplotlib. The problem is some columns have one-level headers, some columns have double-level headers.
Here's what I need:
Here's simple example for one-level headers:
df = pd.DataFrame()
df['Animal'] = ['Cow', 'Bear']
df['Weight'] = [250, 450]
df['Favorite'] = ['Grass', 'Honey']
df['Least Favorite'] = ['Meat', 'Leaves']
df
fig = plt.figure(figsize=(9,2))
ax=plt.subplot(111)
ax.axis('off')
table = ax.table(cellText=df.values, colColours=['grey']*df.shape[1], bbox=[0, 0, 1, 1], colLabels=df.columns)
plt.savefig('Table.jpg')
Last chunk of code produces next picture:
What changes do I need to make to have table I need?
from Double header in Matplotlib Table



No comments:
Post a Comment