子图表中的条件格式化数据条

问题描述 投票:0回答:1
大家好,我已经为此苦苦挣扎了好几天。 我已经设置了一个包含 4 个表和彩色列的子图,我实际上希望它们成为基于列中最小和最大数字的数据条。

我尝试了多种不同的方法,但无法让它发挥作用。我当前的代码如下。

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()
这里是图形输出的副本,我想使用相同的颜色将彩色列更改为数据条。提前感谢您的帮助!

python pandas plotly
1个回答
0
投票
如果您愿意释放

DashDiverging Data Bars 文档中有一个示例可以完美满足您的需求:

你会在链接资源中找到一个完整的片段来重现上图中的表格,但如果你愿意分享你的数据样本,我可以看看如何让它适用于你的特定数据集.

© www.soinside.com 2019 - 2024. All rights reserved.