【问题标题】:Multiple hover_name for 3D plot in Python PlotlyPython Plotly 中 3D 绘图的多个 hover_name
【发布时间】:2021-01-21 00:07:02
【问题描述】:

我想为我的 3D 绘图模型添加更多使用多列的悬停文本。

例如: df:

    sepal_length    sepal_width petal_length    petal_width species species_id
0   5.1             3.5         1.4             0.2         setosa  1
1   4.9             3.0         1.4             0.2         setosa  1
2   4.7             3.2         1.3             0.2         setosa  1
3   4.6             3.1         1.5             0.2         setosa  1
4   5.0             3.6         1.4             0.2         setosa  1
5   5.4             3.9         1.7             0.4         setosa  1

代码:

import plotly.express as px
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
                    color='petal_length', symbol='species', hover_name="species")
fig.show()

制作情节

在图中,hover_name="species"hover_name 中仅显示species。我怎样才能在hover_name 中也包含species_id

【问题讨论】:

    标签: python 3d plotly


    【解决方案1】:

    只需在下面的hover_data 参数中添加其他信息:

    import plotly.express as px
    df = px.data.iris()
    fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
                        color='petal_length', symbol='species', hover_name="species", hover_data=["species", "species_id"])
    fig.show()
    

    文档可以在这里找到Customizing Hover text with Plotly Express

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      • 2023-02-10
      • 2017-01-29
      • 2016-01-02
      • 1970-01-01
      • 2021-06-29
      相关资源
      最近更新 更多