Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seaborn version incompats. #28

Open
rafalcode opened this issue Feb 1, 2022 · 0 comments
Open

seaborn version incompats. #28

rafalcode opened this issue Feb 1, 2022 · 0 comments
Labels
enhancement Improvement for existing functionality

Comments

@rafalcode
Copy link

rafalcode commented Feb 1, 2022

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)

    pearr = stats.pearsonr(TPMs.rep1,TPMs.rep2)
    st=f"Pearson's r = {pearr[0]:.4f}"
    g1.ax_joint.text(0.05, 0.95, st, fontsize=15, transform=g1.ax_joint.transAxes, verticalalignment='top')

Additional context

Proof of concept:

#!/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")
@rafalcode rafalcode added the enhancement Improvement for existing functionality label Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement for existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant