[英]How do I add the p value on the hover of a plotly express heatmap?
With SciPy I get the Spearman correlation and p-values.通过 SciPy,我得到了 Spearman 相关性和 p 值。
With px.imshow from plotly express I get the following plot:使用来自 plotly express 的 px.imshow,我得到以下 plot:
At this moment the hover shows: Feature_1 , Feature_2 and their respective Correlation .此时 hover 显示: Feature_1 、 Feature_2和它们各自的Correlation 。
How do I make the hover also show the p_value ?如何使 hover 也显示p_value ?
If you look at the documentation of plotly.figure_factory.create_annotated_heatmap
, you will not find any attribute to change the hover data.如果您查看
plotly.figure_factory.create_annotated_heatmap
的文档,您将找不到任何更改 hover 数据的属性。 Thus, I suggest using plotly.graph_objects
as follows:因此,我建议使用
plotly.graph_objects
如下:
Code代码
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 Output
You can define features 1 nd 2 by using df.feature1.unique().tolist()
您可以使用
df.feature1.unique().tolist()
定义功能 1 nd 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.