python - 不带空格的情节保存表 [英] python - plotly save table without whitespace
本文介绍了python - 不带空格的情节保存表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 python 中用 plotly 生成一个表,并将其另存为 png .但是保存的 png 有很多空白.我有一个解决方案,即 png/或图像被填充";或全屏/图像".
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".
我用以下方法生成表格:
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
推荐答案
使用此代码:
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")
update_layout
将帮助您修复图表的高度和重量.
the update_layout
will help you to fix the height and weight of the chart.
输出:
这篇关于python - 不带空格的情节保存表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文