-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Description
When using col_wrap, seaborn builds the axes manually using fig.add_subplot (see:
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:
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.
Metadata
Metadata
Assignees
Labels
No labels