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)
对于 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)