[英]How do I add the p value on the hover of a plotly express heatmap?
如果您查看plotly.figure_factory.create_annotated_heatmap
的文档,您将找不到任何更改 hover 数据的属性。 因此,我建议使用plotly.graph_objects
如下:
代码
import numpy as np
import plotly.graph_objects as go
z = np.round(np.random.rand(5,5),2)
p = np.round(np.random.rand(5,5),2)
feature_1 = ['Buttinia1 type',
'Buttinia2 type',
'Buttinia3 type',
'Buttinia4 type',
'Buttinia5 type']
feature_2 = ['Diporopollis aff. assamica',
'Esporas, hifas y/o cuerpos fructiferos',
'Forro de foraminífero',
'Sphaeromorpho',
'Scolecodonte']
hovertext = np.empty(z.shape, dtype=object)
for i, ftr2 in enumerate(feature_2):
for j,ftr1 in enumerate(feature_1):
hovertext[i,j] = f'feature 1: {ftr1}<br />feature 2: {ftr2}<br />Correlation: {z[i,j]}<br />p-value: {p[i,j]}'
fig= go.Figure(go.Heatmap(z=z,
x=feature_1,
y=feature_2,
hoverinfo='text',
hovertext=hovertext,
texttemplate="%{z}"))
fig.show()
Output
您可以使用df.feature1.unique().tolist()
定义功能 1 nd 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.