Multiple calls to FacetGrid.set_titles() create misaligned margin titles
See original GitHub issueI’d like to use multiple calls to FacetGrid.map() to layer multiple outputs. However, the right margin titles become misaligned, because each call to map() triggers an additional set_titles() call, and it appears the inferred bounding box coordinates are changing.
Here’s a minimal working example from v 0.5.1:
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="darkgrid")
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, row="sex", col="time", margin_titles=True)
bins = np.linspace(0, 60, 13)
g.map(plt.hist, "total_bill", color="steelblue", bins=bins, lw=0)
g.map(plt.hist, "total_bill", color="green", bins=bins, lw=0)
The following also reproduces the problem:
g2 = sns.FacetGrid(tips, row="sex", col="time", margin_titles=True)
g2.map(plt.hist, "total_bill", color="steelblue", bins=bins, lw=0)
g2.set_titles()
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Seaborn anonying facet title · Douglas C. Wu
This jupyter notbook intends to record how the facet title from seaborn FacetGrid can be aligned as ggplot2 in R (Because I always...
Read more >Seaborn Facet Grid, Change Title Color For Margin Title Only
Draw titles either above each facet or on the grid margins. ... Multiple calls to FacetGrid.set_titles() create misaligned margin titles #509.
Read more >Customizing annotation with Seaborn's FacetGrid
First, the default titles are drawn in the FacetGrid.map method, so if you want to change the titles, you have to call set_titles...
Read more >What's new in each version — seaborn 0.11.2 documentation
Enhancement Improved FacetGrid.set_titles() with margin_titles=True , such that texts representing the original row titles are removed before adding new ...
Read more >Python for Data Analysis
While “data analysis” is in the title of the book, the focus is specifically on Python programming, libraries, and tools as opposed to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is still an issue in current versions of seaborn and matplotlib. #612 may have improved things for some cases, but I ran into this because the new titles were shorter than the originals.
A comment on #612 says that the hack described here no longer works.
I didn’t realise this was a know issue until coming to report it, so my solution for anyone facing this in the future was the following before the final call to set_titles:
Leaving it there in case it can help anyone in the future.
My figure is a grid of heatmaps that use
annot=True
to display values within the cells. However, the solutions presented here remove all text from the figure before redrawing. Is there a way to only remove the undesired titles and not other text?