为什么 `fig.update_layout` 的 `title_text` 参数似乎不适用于 Jupyter 中的 Plotly table?

Why does the `title_text` argument of `fig.update_layout` appear not to be working for Plotly table in Jupyter?

我在 Plotly Figure Factory table 中展示了一个 Pandas DataFrame,并且 fig.update_layout 中的参数都按预期工作,除了 title_text(示例here).

import pandas as pd
import plotly.figure_factory as ff

df = pd.DataFrame({
    'member': 'A B C D E F G'.split(' '),
    'amount': [515, 45, 315, 321, 43, 244, 433]
})

fig = ff.create_table(df)

fig.update_layout(
    title_text='Titletext'
    autosize=False,
    width=150*df.shape[1],
    height=40*df.shape[0],
)

fig.show()

这会生成具有正确单元格大小的 table,但没有标题 显示在 Jupyter Notebook 输出中

您可能需要调整图的边距。 github 上标记了一个类似的问题:https://www.github.com/plotly/plotly.py/issues/2795

解决方案:fig.update_layout({'margin': {'t': 50}})。这意味着从图的顶部创建一个 50 像素的边距,这样标题就不会从图中“截断”。