Skip to content

Commit

Permalink
Fix PairGrid with hue passed in map method
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Jun 11, 2022
1 parent 8bae24f commit 5e69766
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/releases/v0.12.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Other updates

- |Fix| Fixed a bug in :func:`violinplot` where inner boxes/points could be missing with unpaired split violins (:pr:`2814`).

- |Fix| Fixed a bug in :class:`PairGrid` where and error would be raised when defining `hue` only in the mapping methods (:pr:`2847`).

- |Fix| Subplot titles will no longer be reset when calling :meth:`FacetGrid.map` or :meth:`FacetGrid.map_dataframe` (:pr:`2705`).

- |Fix| In :func:`lineplot`, allowed the `dashes` keyword to set the style of a line without mapping a `style` variable (:pr:`2449`).
Expand Down
7 changes: 4 additions & 3 deletions seaborn/axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,9 +1565,10 @@ def _plot_bivariate(self, x_var, y_var, ax, func, **kwargs):
else:
hue = data.get(self._hue_var)

kwargs.setdefault("hue", hue)
kwargs.setdefault("hue_order", self._hue_order)
kwargs.setdefault("palette", self._orig_palette)
if "hue" not in kwargs:
kwargs.update({
"hue": hue, "hue_order": self._hue_order, "palette": self._orig_palette,
})
func(x=x, y=y, **kwargs)

self._update_legend_data(ax)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,14 @@ def test_hue_order_missing_level(self):

plt.close("all")

def test_hue_in_map(self, long_df):

g = ag.PairGrid(long_df, vars=["x", "y"])
g.map(scatterplot, hue=long_df["a"])
ax = g.axes.flat[0]
points = ax.collections[0]
assert len(set(map(tuple, points.get_facecolors()))) == 3

def test_nondefault_index(self):

df = self.df.copy().set_index("b")
Expand Down

0 comments on commit 5e69766

Please sign in to comment.