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()
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).
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.
jointplot() : Draw a plot of two variables with bivariate and univariate graphs.
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.
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()
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)])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With