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

Example of integrating seaborn.object() #162

Open
TKMarkCheng opened this issue Dec 3, 2023 · 0 comments
Open

Example of integrating seaborn.object() #162

TKMarkCheng opened this issue Dec 3, 2023 · 0 comments

Comments

@TKMarkCheng
Copy link

TKMarkCheng commented Dec 3, 2023

There currently is no guide to integrating adjustText into seaborn, a popular matplotlib wrapper.

This is especially detrimental to seaborn.objects() which aims to have the same grammar as ggplot2, but does not have easy options to space out text like ggrepel.

After testing, I have demonstrated that adjustText can be integrated into seaborn.objects() using principles demonstrated from #58 and using seaborn.objects.Plot.on

Generic solution:

# your plot (with subfigures, can be declared by .facet())
p=so.Plot().add(so.Text())
f=plt.figure(figsize=(24, 10), dpi=200, layout="constrained")
p.on(f).plot()
# In my instance I was using subplots
for ax in f.axes:
    adjust_text(texts=[child for child in ax.get_children() if isinstance(child,mpl.text.Text)][:-3],ax=ax,arrowprops=dict(arrowstyle='-', color='gray', alpha=.65))
#[:-3] because last three Text objects are x-axis, y-axis, and title respectively.

Lastly, regarding the questions about time discrepancy between subplots raised in #58, initially setting a random arbitrary Text location helps speed up the process on my instance.

so.Text(valign='top')

I will push a full example .ipynb once I finish my paper...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant