Remove space under table

Hello,
I am producing a table in Python using the plotly package, but I am struggling with adjusting the space around the table. How do I remove unwanted space beneath my plotly table? I tried adjusting the margin sizes in layout which reduces the top, left and right margins. This has reduced the space at the top, left and right by pushing the table to the top of the container, but a lot of space still remains underneath. The purpose of removing the white space underneath is to embed the table in a HTML email with text above and below the table. Any help would be appreciated. Here’s my code:

table = go.Figure(data=[go.Table(
    header=dict(values=[['From cur.'],['To cur.'],['Table rate'],['FX rate'],['Abs. error (%)']], 
               fill_color='aliceblue',
               line_color='darkslategray', 
               align='left'),
    cells=dict(values=[exr_mismatches['From cur.'], exr_mismatches['To cur.'], exr_mismatches['Table rate'].map('{:.3f}'.format), 
                       exr_mismatches['FX rate'].map('{:.3f}'.format), exr_mismatches['Abs. error (%)'].map('{:.2f}'.format)],
                fill_color='whitesmoke',
                line_color='darkslategray',
                align='left'))
                        ])
table.update_layout(autosize=False, margin=dict(l=5, r=5, b=5, t=5), paper_bgcolor='steelblue')

Hi @zen100 welcome to the forum! The parameter that needs to be changed is the height of the figure layout, for example

import plotly.graph_objects as go

fig = go.Figure(data=[go.Table(header=dict(values=['A Scores', 'B Scores']),
                 cells=dict(values=[[100, 90, 80, 90], [95, 85, 75, 95]]))
                     ])
fig.update_layout(height=100, margin=dict(r=5, l=5, t=5, b=5))
fig.show()

(height and width have default values, which do not adapt to the figure content).
If the contents of the table change and you need to adapt the height of the figure, a workaround is described here.

1 Like