python - plotly save table without whitespace

Viewed 512

i generate a table in python with plotly and i save it as png . but the saved png has a lot of whitespace. i there a solution that the png/or image is "filled" or "Full-screen/image". enter image description here

i generate the table with:

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]]))
                     ])
plotly.io.write_image(fig, file='example_table.png', format='png')

thanks for ideas and solutions. greets alex

1 Answers

Use this code:

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(
    autosize=False,
    margin = {'l':0,'r':0,'t':0,'b':0},
    height = 125
)
fig.write_image("fig1.png")

the update_layout will help you to fix the height and weight of the chart.

Output: enter image description here

Related