Skip to content

Commit 0f5182e

Browse files
authored
Fix issue when an empty palette is provided for an empty dataset (#3136)
* Fix issue when an empty palette is provided for an empty dataset * Added test for empty palette with swarmplot or stripplot
1 parent bf9fcb3 commit 0f5182e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

seaborn/categorical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def _native_width(self):
236236
def _nested_offsets(self, width, dodge):
237237
"""Return offsets for each hue level for dodged plots."""
238238
offsets = None
239-
if "hue" in self.variables:
239+
if "hue" in self.variables and self._hue_map.levels is not None:
240240
n_levels = len(self._hue_map.levels)
241241
if dodge:
242242
each_width = width / n_levels
@@ -268,7 +268,7 @@ def plot_strips(
268268
jlim = 0.1
269269
else:
270270
jlim = float(jitter)
271-
if "hue" in self.variables and dodge:
271+
if "hue" in self.variables and dodge and self._hue_map.levels is not None:
272272
jlim /= len(self._hue_map.levels)
273273
jlim *= self._native_width
274274
jitterer = partial(np.random.uniform, low=-jlim, high=+jlim)

tests/test_categorical.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,9 @@ def test_vs_catplot(self, long_df, wide_df, kwargs):
21372137

21382138
assert_plots_equal(ax, g.ax)
21392139

2140+
def test_empty_palette(self):
2141+
self.func(x=[], y=[], hue=[], palette=[])
2142+
21402143

21412144
class TestStripPlot(SharedScatterTests):
21422145

0 commit comments

Comments
 (0)