Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Seaborn jointplot does not show the correlation coefficient and p-value on the chart

I'm trying to plot jointplot with below and from samples I saw it should show the correlation coefficient and p-value on the chart. However it does not show those values on mine. Any advice? thanks.

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() 
like image 970
user2784820 Avatar asked Aug 31 '18 15:08

user2784820


People also ask

What does a Jointplot show?

A Jointplot comprises three plots. Out of the three, one plot displays a bivariate graph which shows how the dependent variable(Y) varies with the independent variable(X). Another plot is placed horizontally at the top of the bivariate graph and it shows the distribution of the independent variable(X).

What is the advantage of using Jointplot to plot data?

Draw a plot of two variables with bivariate and univariate graphs. This function provides a convenient interface to the JointGrid class, with several canned plot kinds. This is intended to be a fairly lightweight wrapper; if you need more flexibility, you should use JointGrid directly.

What two types of visualizations are shown on a joint plot?

jointplot() : Draw a plot of two variables with bivariate and univariate graphs.

What is joint grid plot in Seaborn?

Either a long-form collection of vectors that can be assigned to named variables or a wide-form dataset that will be internally reshaped. Size of each side of the figure in inches (it will be square). Ratio of joint axes height to marginal axes height. If True, remove missing observations before plotting.


2 Answers

I ended up using below to plot

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() 
like image 158
user2784820 Avatar answered Sep 18 '22 21:09

user2784820


With version >=0.11 of seaborn, jointgrid annotation is removed so you won't see the pearsonr value.

If needed to display, one way is to calculate the pearsonr and put it in the jointplot as a legend.

for example:

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)]) 

enter image description here

like image 28
sambit9238 Avatar answered Sep 19 '22 21:09

sambit9238