Search code examples
pythonpandasmatplotlibmatplotlib-table

How can I increase the size of the table?


I'm trying to display a pandas dataframe as an image, but when I use plt.show(), I got a small picture of the table, inside a big (invisible) subplot, occupying 90% of the generated window.

I used this code:

    # ...

    ax = plt.subplot()

    ax.xaxis.set_visible(False)
    ax.yaxis.set_visible(False)

    ax.spines['right'].set_visible(False)
    ax.spines['top'].set_visible(False)
    ax.spines['left'].set_visible(False)
    ax.spines['bottom'].set_visible(False)

    coeficientes_real_2 = coeficientes_real.transpose()

    table(ax, coeficientes_real_2, colWidths=[0.1, 0.1, 0.1], loc='center')

    plt.savefig('mytable.png')

    plt.show()

    #...

And got this result:

Result

How can I increase the size of the table?


Solution

  • Based on this post, you can scale the whole table with

    tb = table(ax, coeficientes_real_2, colWidths=[0.1, 0.1, 0.1], loc='center')
    tb.scale(2,2)
    

    Or change the column width and font size individually:

    tb = table(ax, coeficientes_real_2, colWidths=2*[0.1, 0.1, 0.1], loc='center')
    tb.set_fontsize(24)