Skip to content Skip to sidebar Skip to footer

Matplotlib Change Font Size Within Table (just Header) - Python

I'd like for the headers of the columns to have a smaller font than the values in the cells so that they're readable (I'll show what I mean in an attached jpeg). Right now everythi

Solution 1:

You could loop over the cells of the table that should get a different font size and set the fontsize in that loop.

cells = the_table1._cells
for cell in the_table1._cells:
    if cell[0] == 0:
        the_table1._cells[cell].set_fontsize(8)

Solution 2:

Here is an example that helped me iterate through the cells with an index tuple("key" in example) to do things like remove borders or set header(row and col headers in this example):

for key, cell in table.get_celld().items():
    # scrub borders for clean look(see source below)
    cell.set_linewidth(0)

    # adjust format for only header col and row to help with space issues
    # col header on 0, row header on -1.
    if key[0] == 0 or key[1] == -1:
        cell.set_fontsize(6)

I appreciate this post by Bart which helped me remove borders in my specific case.


Post a Comment for "Matplotlib Change Font Size Within Table (just Header) - Python"