简体   繁体   English

如何在 Plotly Dash 中过滤热图色阶?

[英]How to filter heatmap colorscale in Plotly Dash?

I am new to plotly dash.我是新来的。 I am trying to create an interactive dashboard where I can filter the colorbar to see the upper values for example if the value is 3000 it was red, so if I type 3000 as input, it is still red but the graph will not show values less than 3000. I am able to add the filtering option but when I filter(I used zmin in go heatmap) the colorscale also changes.我正在尝试创建一个交互式仪表板,我可以在其中过滤颜色条以查看上限值,例如,如果值为 3000,它是红色的,所以如果我输入 3000 作为输入,它仍然是红色的,但图表不会显示更少的值超过 3000。我可以添加过滤选项,但是当我过滤(我在 go heatmap 中使用 zmin)时,色阶也会改变。 Can I keep the previous colorscale so that if I choose zmin, it refreshes the graph with the original colorscale but filters values greater than zmin?我可以保留以前的色阶,以便如果我选择 zmin,它会使用原始色阶刷新图形但过滤大于 zmin 的值? Here is the code I have written so far -这是我到目前为止编写的代码 -

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

Here is the sample output I get-[![enter image description here][1]][1] After filtering- [![enter image description here][2]][2]这是我得到的示例输出-[![在此处输入图像描述][1]][1] 过滤后-[![在此处输入图像描述][2]][2]

I am not completely sure I understood what you mean, but isn't it enough to just filter your data?我不完全确定我理解您的意思,但是仅过滤您的数据还不够吗? I also don't have an example of how you data look like, but why don't you try filtering your data frame before you plot?我也没有你的数据是什么样子的例子,但是你为什么不在你绘制之前尝试过滤你的数据框呢?

data_to_plot = frames[frames['your_column'] > zmin]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM