[英]How to filter heatmap colorscale in Plotly Dash?
我是新來的。 我正在嘗試創建一個交互式儀表板,我可以在其中過濾顏色條以查看上限值,例如,如果值為 3000,它是紅色的,所以如果我輸入 3000 作為輸入,它仍然是紅色的,但圖表不會顯示更少的值超過 3000。我可以添加過濾選項,但是當我過濾(我在 go heatmap 中使用 zmin)時,色階也會改變。 我可以保留以前的色階,以便如果我選擇 zmin,它會使用原始色階刷新圖形但過濾大於 zmin 的值? 這是我到目前為止編寫的代碼 -
app.layout = html.Div(children=[
html.H1(children='Title'),
dcc.Graph(
id='graph',
figure=fig
),
dcc.Input(
id="input", type="number", value=0
)
])
@app.callback(
Output('graph', 'figure'),
Input('input', 'value')
)
def update_figure(input):
frames = []
for d, i in enumerate(sorted(timestamp_list)):
frames.append(
go.Frame(
name=time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(int(i) / 1000)),
data=[
go.Heatmap(z=df_dict[i],
x=df_dict[i].columns,
y=df_dict[i].index,
zmin=input,
zmax=max(value_list))
]
)
)
yaxis_name = kind.split("_")[0]
xaxis_name = kind.split("_")[1]
fig = go.Figure(
data=frames[0].data,
frames=frames,
layout=go.Layout(
autosize=True,
height=800,
yaxis={"title": yaxis_name, "dtick": 1},
xaxis={"title": xaxis_name, "tickangle": 45, "side": 'top'},
),
)
# finally, create the slider
fig.update_layout(
updatemenus=[{
'buttons': [
{
'args': [None, {'frame': {'duration': 500, 'redraw': True},
'transition': {'duration': 500, 'easing': 'quadratic-in-out'}}],
'label': 'Play',
'method': 'animate'
},
{
'args': [[None], {'frame': {'duration': 0, 'redraw': False},
'mode': 'immediate',
'transition': {'duration': 0}}],
'label': 'Pause',
'method': 'animate'
}
],
'direction': 'left',
'pad': {'r': 10, 't': 100},
'showactive': False,
'type': 'buttons',
'x': 0.1,
'xanchor': 'right',
'y': 0,
'yanchor': 'top'
}],
sliders=[{"steps": [{"args": [[f.name], {"frame": {"duration": 0, "redraw": True},
"mode": "immediate", }, ],
"label": f.name, "method": "animate", }
for f in frames],
}]
)
return fig
這是我得到的示例輸出-[![在此處輸入圖像描述][1]][1] 過濾后-[![在此處輸入圖像描述][2]][2]
我不完全確定我理解您的意思,但是僅過濾您的數據還不夠嗎? 我也沒有你的數據是什么樣子的例子,但是你為什么不在你繪制之前嘗試過濾你的數據框呢?
data_to_plot = frames[frames['your_column'] > zmin]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.