我尝试了多种不同的方法,但无法让它发挥作用。我当前的代码如下。
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from plotly.colors import n_colors
fig = make_subplots(
rows=4, cols=1,
subplot_titles=("Backs", "Edges", "Middles", "Halves, Hookers"),
shared_xaxes=True,
vertical_spacing=0.02,
specs=[[{"type": "table"}],
[{"type": "table"}],
[{"type": "table"}],
[{"type": "table"}]]
)
fig.add_trace(
go.Table(
header=dict(
values=list(Backs_cleaned.columns),
fill_color='maroon',
font=dict(size=10),
font_color='white',
line_color='lightgrey',
align="center"
),
cells=dict(
values=[Backs_cleaned.Round_x, Backs_cleaned.Name, Backs_cleaned.Minutes_x, Backs_cleaned.Game_x, Backs_cleaned.Con_x,
Backs_cleaned.Round_y,Backs_cleaned.Minutes_y, Backs_cleaned.Game_y, Backs_cleaned.Con_y, Backs_cleaned.Sum],
font=dict(size=10),
fill=dict(color=['white', 'white', 'lightgreen', 'salmon', 'lightgoldenrodyellow', 'white','lightgreen', 'salmon', 'lightgoldenrodyellow', 'white']),
font_color='black',
line_color='lightgrey',
align = "center"),
),
row=1, col=1
)
fig.add_trace(
go.Table(
header=dict(
values=list(Edges_cleaned.columns),
fill_color='maroon',
font=dict(size=10),
font_color='white',
line_color='lightgrey',
align="center"
),
cells=dict(
values=[Edges_cleaned.Round_x, Edges_cleaned.Name, Edges_cleaned.Minutes_x, Edges_cleaned.Game_x, Edges_cleaned.Con_x,
Edges_cleaned.Round_y,Edges_cleaned.Minutes_y, Edges_cleaned.Game_y, Edges_cleaned.Con_y, Edges_cleaned.Sum],
fill=dict(color=['white', 'white', 'lightgreen', 'salmon', 'lightgoldenrodyellow', 'white','lightgreen', 'salmon', 'lightgoldenrodyellow', 'white']),
font=dict(size=10),
font_color='black',
line_color='lightgrey',
align = "center")
),
row=2, col=1
)
fig.add_trace(
go.Table(
header=dict(
values=list(Middles_cleaned.columns),
fill_color='maroon',
font=dict(size=10),
font_color='white',
line_color='lightgrey',
align="center"
),
cells=dict(
values=[Middles_cleaned.Round_x, Middles_cleaned.Name, Middles_cleaned.Minutes_x, Middles_cleaned.Game_x, Middles_cleaned.Con_x,
Middles_cleaned.Round_y,Middles_cleaned.Minutes_y, Middles_cleaned.Game_y, Middles_cleaned.Con_y, Middles_cleaned.Sum],
fill=dict(color=['white', 'white', 'lightgreen', 'salmon', 'lightgoldenrodyellow', 'white','lightgreen', 'salmon', 'lightgoldenrodyellow', 'white']),
font=dict(size=10),
font_color='black',
line_color='lightgrey',
align = "center")
),
row=3, col=1
)
fig.add_trace(
go.Table(
header=dict(
values=list(HH_cleaned.columns),
fill_color='maroon',
font=dict(size=10),
font_color='white',
line_color='lightgrey',
align="center"
),
cells=dict(
values=[HH_cleaned.Round_x, HH_cleaned.Name, HH_cleaned.Minutes_x, HH_cleaned.Game_x, HH_cleaned.Con_x,
HH_cleaned.Round_y,HH_cleaned.Minutes_y, HH_cleaned.Game_y, HH_cleaned.Con_y, HH_cleaned.Sum],
fill=dict(color=['white', 'white', 'lightgreen', 'salmon', 'lightgoldenrodyellow', 'white','lightgreen', 'salmon', 'lightgoldenrodyellow', 'white']),
font=dict(size=10),
font_color='black',
line_color='lightgrey',
align = "center")
),
row=4, col=1
)
fig.update_layout(
height=1600,
showlegend=False,
title_text="Longitudinal Conditioning Minutes",
)
fig.show()
这里是图形输出的副本,我想使用相同的颜色将彩色列更改为数据条。提前感谢您的帮助!
Dash,Diverging Data Bars 文档中有一个示例可以完美满足您的需求:
你会在链接资源中找到一个完整的片段来重现上图中的表格,但如果你愿意分享你的数据样本,我可以看看如何让它适用于你的特定数据集.