Python Seaborn jointplot不显示图表上的相关系数和p值

use*_*820 11 python matplotlib seaborn

我试图用下面的样本绘制联合图,我从样本中看到它应该在图表上显示相关系数和p值.然而,它并没有显示我的这些价值观.有什么建议?谢谢.

import seaborn as sns
sns.set(style="darkgrid", color_codes=True)
sns.jointplot('Num of A', ' Ratio B', data = data_df, kind='reg', height=8)
plt.show()
Run Code Online (Sandbox Code Playgroud)

use*_*820 17

我最终使用下面的情节

import seaborn as sns
import scipy.stats as stats

sns.set(style="darkgrid", color_codes=True)
j = sns.jointplot('Num of A', ' Ratio B', data = data_df, kind='reg', height=8)
j.annotate(stats.pearsonr)
plt.show()
Run Code Online (Sandbox Code Playgroud)

  • 被低估的问题/答案对.令人讨厌的是,他们毫不客气地弃用了"stat_func",并且在文档中没有明显的解决方法.我觉得这篇SE帖子随着时间变得越来越受欢迎...... (2认同)
  • 为我工作,但收到此警告:“JointGrid 注释已弃用,将在未来版本中删除。” (2认同)

sam*_*238 9

对于 seaborn >=0.11 的版本,jointgrid 注释被删除,因此您不会看到 pearsonr 值。

如果需要显示,一种方法是计算pearsonr并将其作为图例放在jointplot中。

例如:

import scipy.stats as stats
graph = sns.jointplot(data=df,x='x', y='y')
r, p = stats.pearsonr(x, y)
# if you choose to write your own legend, then you should adjust the properties then
phantom, = graph.ax_joint.plot([], [], linestyle="", alpha=0)
# here graph is not a ax but a joint grid, so we access the axis through ax_joint method

graph.ax_joint.legend([phantom],['r={:f}, p={:f}'.format(r,p)])
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

  • 到目前为止,这是唯一真正提供解决方法的答案。 (2认同)

小智 5

此功能已在 Seaborn v0.9.0(2018 年 7 月)中弃用:

弃用了 JointGrid 的统计注释组件。该方法仍然可用,但将在未来版本中删除。(来源