question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple calls to FacetGrid.set_titles() create misaligned margin titles

See original GitHub issue

I’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()

factorgrid_titles

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
parchd-1commented, Jul 18, 2017

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:

for row in g.axes:
    row[-1].texts = []

Leaving it there in case it can help anyone in the future.

0reactions
mmmatthewcommented, Apr 16, 2019

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found