Centered text in matplotlib tables
3 answers
Another answer, which edits cell alignment individually, serves this case and is more general, where only arbitrary columns (but not all) need to be centered (or any specific cells in that case).
Let's say you have a table with 5 rows - 3 columns. If you only want to edit the 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 on this until I looked at the table.py
source
0
source to share