I am trying to center the text inside a matplotlib table cell, while the default seems to be right aligned. I looked through the documentation of the Table object, but I cou
Another answer which edits the cell's alignment individually, serves this case and a more general one where only arbitrary columns (but not all) are to be centered (or any specific cells to that case).
Let's say you have a 5 rows - 3 columns table. If you want to edit only first column:
the_table = plt.table(cellText=cell_text,
rowLabels=rows,
rowColours=colors,
colLabels=columns,
loc='bottom')
cells = the_table.properties()["celld"]
for i in range(0, 5):
cells[i, 0]._loc = 'center'
I was stuck with this until I took a look at table.py
source