You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe
Seaborn v11.2 has totally dropped the JointGrid.annotate() method after previous version threw warnings saying it would be deprecated which causes an issue with the scatter_plots.py script in the bin directory.
Describe the solution you'd like
A way of inserting the Pearson's R value text into the top left corner of the scatterplots that also works on Seaborn v.0.11.2 and also on legacy v0.9.0.
Describe alternatives you've considered
Use Matplotlib's Axes text() feature, which Seaborn allows, though a simple top left positioning requires some "chewing" and Pearson's r has to be precalculated because this method does not accept a function, and has no convenient positioning via loc as annotate() used to.
The following could possibly do it (at line 35 bin/scatter_plots.py)
#!/usr/bin/env python3
# This works for both Seaborn v0.9.0 and v0.11.2
import seaborn as sns
from scipy import stats
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
g = sns.JointGrid(x="total_bill", y="tip", data=tips)
g = g.plot_joint(plt.scatter, color="g", s=40, edgecolor="white")
g = g.plot_marginals(sns.distplot, kde=False, color="g")
# OK here is the deprecated annotate function, This will only work in v0.9.0 with deprecation warning.
# g = g.annotate(stats.pearsonr, template="{stat}: {val:.4f}", stat="Pearson's r", loc="upper left", fontsize=15)
# alternative requires a few more lines:
pearr= stats.pearsonr(tips.total_bill, tips.tip) # precalc
st=f"Pearson's r = {pearr[0]:.4f}" # stringify
g.ax_joint.text(0.05, 0.95, st, fontsize=15, transform=g.ax_joint.transAxes, verticalalignment='top')
g.savefig("d09.pdf", format="pdf")
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe
Seaborn v11.2 has totally dropped the
JointGrid.annotate()
method after previous version threw warnings saying it would be deprecated which causes an issue with thescatter_plots.py
script in the bin directory.Describe the solution you'd like
A way of inserting the Pearson's R value text into the top left corner of the scatterplots that also works on Seaborn v.0.11.2 and also on legacy v0.9.0.
Describe alternatives you've considered
Use Matplotlib's Axes
text()
feature, which Seaborn allows, though a simple top left positioning requires some "chewing" and Pearson's r has to be precalculated because this method does not accept a function, and has no convenient positioning vialoc
asannotate()
used to.The following could possibly do it (at line 35
bin/scatter_plots.py
)Additional context
Proof of concept:
The text was updated successfully, but these errors were encountered: