最佳答案
既然您专门询问如何
add them inside the yellow box
您并不是真正询问如何注释 3D 图表,否则您可以使用 3D annotations 来完成此操作,但实际上如何自定义悬停信息。如果您愿意使用plotly.express
,您可以在 px.scatter_3D()
中使用 custom_data
来包含有关散点图中未显示的第四个变量的信息:
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
color='petal_length', size='petal_length', size_max=18,
symbol='species', opacity=0.7,
custom_data = ['category']
)
temp1 = fig.data[0].hovertemplate
fig.update_traces(hovertemplate = temp1 + '<br>' + "Category: %{customdata[0]}")
完整代码:
import plotly.express as px
df = px.data.iris()
category = {'setosa':'flower', 'versicolor': 'vegetable', 'virginica': 'not a flower'}
df['category'] = df['species'].map(category)
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
color='petal_length', size='petal_length', size_max=18,
symbol='species', opacity=0.7,
custom_data = ['category']
)
temp1 = fig.data[0].hovertemplate
fig.update_traces(hovertemplate = temp1 + '<br>' + "Category: %{customdata[0]}")
fig.update_layout(margin=dict(l=0, r=0, b=0, t=0))
fig.show()
关于python - Plotly 3D 绘图注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68262505/