modify horizontal alignment in Matplotlib table
<p>The matplotlib.table.Table class is NOT documented, and is very hard to understand the logic...</p>

<p>I can change the font, but not the "horizontalalignment" !</p>

<pre><code>import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
fig = plt.figure(figsize=(20,16))
ax1 = fig.add_subplot(1,1,1)
columns = ["label1","label2","label3"]
cell_text = [['1', '2', '3'], ['4', '5', '6']]
fontname = os.path.join(matplotlib.get_data_path(),
                            'fonts', 'ttf', 'cmex10.ttf')
fig.subplots_adjust(left=0.02, bottom=0.05, right=0.70, top=0.92)
table=ax1.table(cellText=cell_text,colLabels=columns,loc='right',
                    colWidths=[.035]*len(columns))
table.set_fontsize(48)
table.scale(1.9,2.5)
for key, cell in table.get_celld().items():
    row, col = key
    #if row &gt; 0 and col &gt; 0:
    cell.get_text().set_horizontalalignment('left') # this should work...
    cell.set_text_props(horizontalalignment='left') # this also...

    if row ==1:
        cell.set_text_props(fontproperties=FontProperties(fname=fontname)) # This does work!
        cell.get_text().set_color('#ff0000') # this also works !

fig.show()
print(cell.get_text().get_horizontalalignment()) # this print 'left' as expected. But after a "fig.savefig('image.png')" is prints "right" ...
</code></pre>

<p>This code produces :
<a href="https://i.stack.imgur.com/MTSgA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MTSgA.png" alt="table resulting from above code"></a>
We see that the row ['1', '2', '3'] used the strange font, and is in red.
But the headers are still "centered" and the table data is right align not left.</p>

<p>The order in which the "set_fontsize" "scale" and the for loop give slightly different result. </p>

<p>matplotlib.table code is to read here : <a href="https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/table.py" rel="nofollow noreferrer">https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/table.py</a> </p>