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 could not find anything useful in this.
Is there an easy way to achieve the centering?
MatPlotLib with PythonPlace legend using legend() method and initialize a method. Iterate the legend. get_texts() method to set the horizontal alignment. To display the figure, use show() method.
BboxTransformTo is a transformation that linearly transforms points from the unit bounding box to a given Bbox. In your case, the transform itself is based upon a TransformedBBox which again has a Bbox upon which it is based and a transform - for this nested instance an Affine2D transform.
Try editing the sample here
Adding
cellLoc='center'
To
the_table = plt.table(cellText=cell_text,
rowLabels=rows,
rowColours=colors,
colLabels=columns,
loc='bottom')
To get
According to documentation, there is this metthod in cell object :
set_text_props(self, **kwargs)
kwargs may refers to text methods/attribute, such this one:
horizontalalignment or ha = [ 'center' | 'right' | 'left' ]
So, what about :
cell.set_text_props(ha='center')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With