如何在 python 中创建一个 plotly figure factory 子图?

How to create a plotly figure factory subplots in python?

示例数据

import seaborn as sns

sample = sns.load_dataset("tips")

图工厂地块

import plotly.figure_factory as ff
fig =  ff.create_table(sample.head())
fig.show()

我想并排绘制 sample.head()sample.tail() 作为子图 create_table()

如何在 plotly 中使用 ff.create_table() 绘制子图?

我建议使用 https://plotly.com/python/table/ and https://plotly.com/python/subplots/

使用示例数据:

import seaborn as sns
import plotly.figure_factory as ff
import plotly.graph_objects as go
from plotly.subplots import make_subplots

sample = sns.load_dataset("tips")

fig = make_subplots(
    rows=1,
    cols=2,
    specs=[[{"type": "table"} for _ in range(2)]],
)

fig.add_trace(
    go.Table(
        cells={"values": sample.head().values.T}, header={"values": sample.columns}
    ),
    row=1,
    col=1,
)
fig.add_trace(
    go.Table(
        cells={"values": sample.tail().values.T}, header={"values": sample.columns}
    ),
    row=1,
    col=2,
)