gpt4 book ai didi

python - 禁用向下滚动并以绘图方式显示表格上的所有数据

转载 作者:行者123 更新时间:2023-12-04 13:55:51 25 4
gpt4 key购买 nike

我使用 plotly 创建了一个表格来计算一些财务,我想在图形界面中显示整个表格(不仅仅是几行):
img
正如您在图像中看到的,我的 30 行中只显示了 11 行。我想显示表的所有数据(没有滚动条的所有 30 行)。
该表的代码如下:

fig6 = go.Figure(data=[go.Table(
header=dict(values=list(df_table.columns),
fill_color='#d3d3d3',
align='left'),
cells=dict(values=[df_table['date'],
df_table['P/E_Ratio'],
df_table['Stock Price']],
fill_color='white',
align='left'))
])

最佳答案

正如胡安所说,添加 heightfig6.update_layout()会做的伎俩。但是,如果您正在寻找更动态的解决方法,则可以使用此函数来计算输入数据框时的高度 -

def calc_table_height(df, base=208, height_per_row=20, char_limit=30, height_padding=16.5):
'''
df: The dataframe with only the columns you want to plot
base: The base height of the table (header without any rows)
height_per_row: The height that one row requires
char_limit: If the length of a value crosses this limit, the row's height needs to be expanded to fit the value
height_padding: Extra height in a row when a length of value exceeds char_limit
'''
total_height = 0 + base
for x in range(df.shape[0]):
total_height += height_per_row
for y in range(df.shape[1]):
if len(str(df.iloc[x][y])) > char_limit:
total_height += height_padding
return total_height
如果您有不同的 font_size,您可能需要尝试其他功能。比默认值,或者如果您更改 margin从默认。另外, char_limit该函数的参数是另一个弱点,因为某些字符比其他字符占用更多空间,大写字符占用更多空间,并且单个单词 if long 可以强制扩展行。如果数量或列数较少,也应该增加,反之亦然。该函数的编写考虑了 4 个表列。
您必须添加 fig6.update_layout(height=calc_table_height(df_table))使其工作。

关于python - 禁用向下滚动并以绘图方式显示表格上的所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62597999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com