diff --git a/seaborn/categorical.py b/seaborn/categorical.py index cd2bfe4aa6..e22d301b75 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -236,7 +236,7 @@ def _native_width(self): def _nested_offsets(self, width, dodge): """Return offsets for each hue level for dodged plots.""" offsets = None - if "hue" in self.variables: + if "hue" in self.variables and self._hue_map.levels is not None: n_levels = len(self._hue_map.levels) if dodge: each_width = width / n_levels @@ -268,7 +268,7 @@ def plot_strips( jlim = 0.1 else: jlim = float(jitter) - if "hue" in self.variables and dodge: + if "hue" in self.variables and dodge and self._hue_map.levels is not None: jlim /= len(self._hue_map.levels) jlim *= self._native_width jitterer = partial(np.random.uniform, low=-jlim, high=+jlim) diff --git a/tests/test_categorical.py b/tests/test_categorical.py index 8b84c40801..1e175991da 100644 --- a/tests/test_categorical.py +++ b/tests/test_categorical.py @@ -2137,6 +2137,9 @@ def test_vs_catplot(self, long_df, wide_df, kwargs): assert_plots_equal(ax, g.ax) + def test_empty_palette(self): + self.func(x=[], y=[], hue=[], palette=[]) + class TestStripPlot(SharedScatterTests):