Sunburst图 - 智能悬停数据 - plotly.xpackress

发布于 2025-02-03 13:39:00 字数 1207 浏览 3 评论 0原文

我想知道是否有一个选项可以将悬停的数据在我的情节表达阳光图上更加聪明,仅显示某些元素,具体取决于我的鼠标结束了哪个部分。请参阅我在下面使用的代码创建图表:

import plotly.express as px
import pandas as pd

data = {'first_column':  ['value_1', 'value_2', 'value_3', 'value_4', 'value_5', 'value_6'],
    'second_column': ['North', 'East', 'South', 'West', 'North', 'North'],
    'third_column': [11, 1, 7, 9, 5, 2],
    'fourth_column':[9,9,7,6,5,4]
    }

df = pd.DataFrame(data)

fig = px.sunburst(
    data_frame=df,
    path=["first_column", "second_column"],
    color = "first_column",
    values="third_column",
    color_discrete_sequence=px.colors.qualitative.Pastel,
    maxdepth=2,
    custom_data=['fourth_column'],
    hover_name="first_column",
    # hover_data={"fourth_column":True},
    template='ggplot2',
)

fig.update_traces(hovertemplate=('<br><b>The third_column is</b>: %{value}<br>'+\
                            '<br><b>The third_column is</b>: %{customdata[0]}<br>'))

fig.show()

例如,如果鼠标在某个段上,是否有办法停止显示自定义数据的悬停数据?即,删除粉红色小脚的文字在朝阳的某些段中所在的地方?

示例Sunburst Digram

感谢提前的帮助。

I was wondering whether there is an option to make the hover data on my plotly express sunburst diagram a bit more intelligent, and only display certain elements depending which segment my mouse is over. See the code I am using below to create the diagram:

import plotly.express as px
import pandas as pd

data = {'first_column':  ['value_1', 'value_2', 'value_3', 'value_4', 'value_5', 'value_6'],
    'second_column': ['North', 'East', 'South', 'West', 'North', 'North'],
    'third_column': [11, 1, 7, 9, 5, 2],
    'fourth_column':[9,9,7,6,5,4]
    }

df = pd.DataFrame(data)

fig = px.sunburst(
    data_frame=df,
    path=["first_column", "second_column"],
    color = "first_column",
    values="third_column",
    color_discrete_sequence=px.colors.qualitative.Pastel,
    maxdepth=2,
    custom_data=['fourth_column'],
    hover_name="first_column",
    # hover_data={"fourth_column":True},
    template='ggplot2',
)

fig.update_traces(hovertemplate=('<br><b>The third_column is</b>: %{value}<br>'+\
                            '<br><b>The third_column is</b>: %{customdata[0]}<br>'))

fig.show()

Is there a way for instance to stop the hover data displaying the custom data, if the mouse is over a certain segment? I.e. remove text where the pink squiggle is for certain segments of the sunburst?

example sunburst diagram

Thanks for the help in advance.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文