diff --git a/seaborn/distributions.py b/seaborn/distributions.py index 9d96eef738..e7643e814d 100644 --- a/seaborn/distributions.py +++ b/seaborn/distributions.py @@ -366,7 +366,7 @@ def violinplot(vals, groupby=None, inner="box", color=None, positions=None, x = positions[i] # If we only have a single value, plot a horizontal line - if len(a) == 1: + if len(np.unique(a)) == 1: y = a[0] if vert: ax.plot([x - widths / 2, x + widths / 2], [y, y], **inner_kws) diff --git a/seaborn/tests/test_distributions.py b/seaborn/tests/test_distributions.py index d7ffff42c5..c28f7f46c5 100644 --- a/seaborn/tests/test_distributions.py +++ b/seaborn/tests/test_distributions.py @@ -284,6 +284,12 @@ def test_multi_violins_single_obs(self): nt.assert_equal(len(ax.lines), 11) plt.close("all") + data = [np.random.randn(30), [0, 0, 0]] + ax = dist.violinplot(data) + nt.assert_equal(len(ax.collections), 1) + nt.assert_equal(len(ax.lines), 6) + plt.close("all") + @classmethod def teardown_class(cls): """Ensure that all figures are closed on exit."""