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

Setting share{x,y} to row/col in FacetGrid does not work when col_wrap=True #3671

Open
temetski opened this issue Apr 8, 2024 · 0 comments · May be fixed by #3672
Open

Setting share{x,y} to row/col in FacetGrid does not work when col_wrap=True #3671

temetski opened this issue Apr 8, 2024 · 0 comments · May be fixed by #3672

Comments

@temetski
Copy link

temetski commented Apr 8, 2024

When using col_wrap, seaborn builds the axes manually using fig.add_subplot (see:

seaborn/seaborn/axisgrid.py

Lines 474 to 490 in ae7acf0

else:
# If wrapping the col variable we need to make the grid ourselves
if gridspec_kws:
warnings.warn("`gridspec_kws` ignored when using `col_wrap`")
n_axes = len(col_names)
axes = np.empty(n_axes, object)
axes[0] = fig.add_subplot(nrow, ncol, 1, **subplot_kws)
if sharex:
subplot_kws["sharex"] = axes[0]
if sharey:
subplot_kws["sharey"] = axes[0]
for i in range(1, n_axes):
axes[i] = fig.add_subplot(nrow, ncol, i + 1, **subplot_kws)
axes_dict = dict(zip(col_names, axes))
).

This breaks the use of col/row for share{x,y} because add_subplot references a base axis, which is always set to axes_0.
Changing the reference axes to one on each row/column fixes this.

Example:

import seaborn as sns
tips = sns.load_dataset("tips")
tips.loc[tips['size']==6, 'tip'] += 100 # create a obvious skew in data
g = sns.FacetGrid(tips, col="size", col_wrap=3, sharey='row')
g.map_dataframe(sns.scatterplot, x="total_bill", y="tip")

The current implementation produces:
image

Suggested behavior:
image

Note that the first row is unaffected by the skewed data in the second row.

I have a working patch in my fork that I can submit as a PR, if this behavior makes sense.

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

Successfully merging a pull request may close this issue.

1 participant