Skip to content

Commit

Permalink
Fix violinplot with multiple identical values
Browse files Browse the repository at this point in the history
Closes #368
  • Loading branch information
mwaskom committed Nov 21, 2014
1 parent c465628 commit 7a4da30
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion seaborn/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions seaborn/tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 7a4da30

Please sign in to comment.