混合图组合 Plotly 表达 scatter 和 go.Table
我想生成一个 2col、1 行的子图:
- row1,col1: px.scatterplot
- row1,col2: go.Table
我无法将这些数字放在一起,这是到目前为止的代码,它生成表格,注释掉的是 px.scatter :
import plotly.express as px
df = px.data.iris()
fig = make_subplots(
rows=1, cols=2,
shared_xaxes=False,
vertical_spacing=0.03,
specs=[[{"type": "scatter"}, {"type": "table"}]]
)
#HERE IS THE PX.SCATTER PLOT (commented out since i cannot add it)
# fig1 = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig.add_trace(
go.Table(
header=dict(
values=list(df.columns),
font=dict(size=10),
align="left"
),
cells=dict(values=[df.sepal_length, df.sepal_width, df.petal_length, df.petal_width, df.species, df.species_id],
fill_color='lavender',
align='left')
),
row=1, col=2
)
fig.show()
I want to generate a subplot figure with 2col, 1 row with:
- row1,col1: px.scatter plot
- row1,col2: go.Table
I am unable to put the figures together, this is the code so far, it generates the table, and commented out is the px.scatter :
import plotly.express as px
df = px.data.iris()
fig = make_subplots(
rows=1, cols=2,
shared_xaxes=False,
vertical_spacing=0.03,
specs=[[{"type": "scatter"}, {"type": "table"}]]
)
#HERE IS THE PX.SCATTER PLOT (commented out since i cannot add it)
# fig1 = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig.add_trace(
go.Table(
header=dict(
values=list(df.columns),
font=dict(size=10),
align="left"
),
cells=dict(values=[df.sepal_length, df.sepal_width, df.petal_length, df.petal_width, df.species, df.species_id],
fill_color='lavender',
align='left')
),
row=1, col=2
)
fig.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你已经完成了所有的辛苦工作!这只是迭代轨迹并添加到子图的情况。
You have done all the hard work! It's just a case of iterating over traces and adding to sub-plot.
我无法在子图中使用plotly.express,因此我对两者都使用了图形对象。为什么要使用plotly,express?
I couldn't use plotly.express in the subplot, so I used graph objects for both. why do you want to use plotly,express?