Sunburst图 - 智能悬停数据 - plotly.xpackress
我想知道是否有一个选项可以将悬停的数据在我的情节表达阳光图上更加聪明,仅显示某些元素,具体取决于我的鼠标结束了哪个部分。请参阅我在下面使用的代码创建图表:
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()
例如,如果鼠标在某个段上,是否有办法停止显示自定义数据的悬停数据?即,删除粉红色小脚的文字在朝阳的某些段中所在的地方?
感谢提前的帮助。
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?
Thanks for the help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论