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

FacetGrid: margin_titles=True clasesh with non-default row_template set up in set_titles #2161

Closed
jpotoniec opened this issue Jul 9, 2020 · 3 comments

Comments

@jpotoniec
Copy link

Dear all,
consider the following code:

import seaborn as sns
tips = sns.load_dataset("tips")
plot = sns.relplot(x="total_bill", y="tip", row="day", data=tips, facet_kws={'margin_titles': True})
plot.set_titles(None, "{row_name}")

What I would expect here is four charts, each denoted with the day of the week on the right-hand side. Instead, I get the picture presented below, where there are clearly two labels on top of each other on the right-hand sides of the charts: one label as requrested, only the day of the week, the other following the default template {row_var} = {row_name} and thus containing the name of the variable as well as its value.

I believe the bug arises from calling set_titles() without any arguments in FacetGrid._finalize_grid. It does work correctly when margin_titles=False, because it relies on Ax.set_title, which seems to not render the text immediately. For the same reason, it works correctly for columns when margin_titles=True. However, the code responsible for annotating rows relies on Ax.annotate instead, which seems to perform rendering immediately.

As a temporary workaround it is possible to remove the call to set_titles() in FacetGrid._finalize_grid in seaborn/axisgrid.py, currently line 893, but I assume this call is there on purpose and permanently removing it would break other cases.

wrong

@mwaskom
Copy link
Owner

mwaskom commented Jul 9, 2020

I think #2083 fixes this. It looks fine for me on master.

margin_titles is basically a hack as matplotlib doesn't offer this functionality through their actual title API. But it works a little bit better now.

@jpotoniec
Copy link
Author

Ah, I admit I didn't check against the current master. My bad, it indeed works correctly in the development version.

@mwaskom
Copy link
Owner

mwaskom commented Jul 9, 2020

No worries, it was a long-standing issue....

Be aware that the master branch is undergoing heavy development right now.

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

2 participants