多个滤镜数据下拉表与python中的绘图

发布于 2025-02-09 13:29:21 字数 1365 浏览 2 评论 0原文

我目前正在尝试生成具有多个下拉选项的表(在木星笔记本中)。我已经能够创建场景,但是下拉按钮可以独立工作,这意味着,如果我从“决定”下拉列表中选择一个下拉列表,则使用选项“选项A或选项2取决于上次选定的按钮。但是,我真正想要的是同时应用两个过滤器。因此,我会得到所有决定“女性”作为我桌子的过滤器的所有决定。

这是我的代码:

fig = go.Figure(go.Table(header={"values": df_dash.columns,'fill_color':'navy','align':'left',
                                 'font':dict(color='white', size=12)}, 
                         cells={"values": df_dash.T.values,'fill_color':'white','align':'left'}))
fig.update_layout(
    updatemenus=[
        {
            "y": 1 - (i / 5),
            "buttons": [
                {
                    "label": c,
                    "method": "restyle",
                    "args": [
                        {
                            "cells": {
                                "values": df_dash.T.values
                                if c == "All"
                                else df_dash.loc[df_dash[menu].eq(c)].T.values
                            }
                        }
                    ],
                }
                for c in ["All"] + df_dash[menu].unique().tolist()
                
            ],
            
        }
        for i, menu in enumerate(["Decision", "Sex",])
    ]
)

这就是外观:

“

任何想法我在做什么错或我能添加什么要使两个按钮同时主动过滤我的DF表?

I am currently trying to generate a table with multiple dropdown options (in a Jupiter Notebook). I have been able to create the scenario but the dropdown buttons work independently, meaning that if I select one dropdown from my 'Decision' dropdown with option 'A' and then select the other downtown 'Sex' with option 'Female' I either get option A or option 2 depending on the button last selected. However, what I really want is to have both filters applied at the same time. So I would get all Decisions 'A' that are 'Female' as filters for my table.

This is my code:

fig = go.Figure(go.Table(header={"values": df_dash.columns,'fill_color':'navy','align':'left',
                                 'font':dict(color='white', size=12)}, 
                         cells={"values": df_dash.T.values,'fill_color':'white','align':'left'}))
fig.update_layout(
    updatemenus=[
        {
            "y": 1 - (i / 5),
            "buttons": [
                {
                    "label": c,
                    "method": "restyle",
                    "args": [
                        {
                            "cells": {
                                "values": df_dash.T.values
                                if c == "All"
                                else df_dash.loc[df_dash[menu].eq(c)].T.values
                            }
                        }
                    ],
                }
                for c in ["All"] + df_dash[menu].unique().tolist()
                
            ],
            
        }
        for i, menu in enumerate(["Decision", "Sex",])
    ]
)

And this is how it looks:

Table view

Any ideas what am I doing wrong or what can I add to make both buttons actively filtering my df table at the same time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏至、离别 2025-02-16 13:29:21

基于这个答案 ,您无法创建彼此依赖的按钮。

您可能会做的最好的方法是创建一个下拉列表,并在当前决策>和sex下拉列表中使用所有可能的组合 - 我理解这可能不是理想的。

如果您愿意使用plotly-dash,那么您可以创建两个下拉列表,这些下拉列表是更新无花果的基本回调的输入,如此示例在Plotly-Dash文档中

Based on this answer in the plotly forums, you cannot create buttons that are dependent on each other.

The best you could probably do is create one dropdown with every possible combination in your current Decision and Sex dropdowns – which I understand probably isn't ideal.

If you are willing to use plotly-dash, then it is possible as you can create two dropdowns that are inputs to a basic callback that updates the fig, as shown in this example in the plotly-dash documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文