Hello Stackoverflow community,
I'm trying to create a matplotlib table with (roughly) 135 columns and (roughly) 10 rows. Some rows contain integers while others contain rounded floats. As a minimal working example I created the following code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
cellContentsArray = np.random.random_integers(0, 100, (10, 135))
df = pd.DataFrame(cellContentsArray,dtype=object)
df.iloc[2] = np.round(np.random.random((1, 135)),2)
df.iloc[7] = np.round(np.random.random((1, 135)),2)
fig, ax = plt.subplots()
fig.patch.set_visible(False) # hide axes
ax.axis('off')
ax.axis('tight')
rowLabelsArray = ['Row label 1','Row label 2','Row label 3','Row label 4','Row label 5','Row label 6','Row label 7','Row label 8','Row label 9','Row label 10']
cellTextArray = df.values
colLabelsArray = df.iloc[0].values
tab = ax.table(cellText=cellTextArray,rowLabels=rowLabelsArray,colLabels=colLabelsArray,loc='center',cellLoc='center')
tab.auto_set_font_size(False)
tab.set_fontsize(5)
tab.scale(1.0,0.6)
fig.tight_layout()
plt.show()
This code produces the following output:
As you can see (or maybe not as every cell text is very tiny) the values are displayed correctly but unfortunately the space is not exploited optimally and the content is not really readable. I already tried setting different parameters with no success so far. How would I go about adjusting this table to use the available space completely while making sure that there is no overlap of text from different table cells?
Any help would be highly appreciated. Thank you very much!