Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix violin 'box' #3405

Merged
merged 2 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions holoviews/plotting/bokeh/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,23 +347,22 @@ def _kde_data(self, el, key, **kwargs):
if not len(values):
pass
elif self.inner == 'quartiles':
for stat_fn in self._stat_fns:
stat = stat_fn(values)
if len(xs):
if len(xs):
for stat_fn in self._stat_fns:
stat = stat_fn(values)
sidx = np.argmin(np.abs(xs-stat))
sx, sy = xs[sidx], ys[sidx]
else:
continue
segments['x'].append(sx)
segments['y0'].append(key+(-sy[-1],))
segments['y1'].append(sy)
segments['x'].append(sx)
segments['y0'].append(key+(-sy[-1],))
segments['y1'].append(sy)
elif self.inner == 'stick':
for value in values:
sidx = np.argmin(np.abs(xs-value))
sx, sy = xs[sidx], ys[sidx]
segments['x'].append(sx)
segments['y0'].append(key+(-sy[-1],))
segments['y1'].append(sy)
if len(xs):
for value in values:
sidx = np.argmin(np.abs(xs-value))
sx, sy = xs[sidx], ys[sidx]
segments['x'].append(sx)
segments['y0'].append(key+(-sy[-1],))
segments['y1'].append(sy)
elif self.inner == 'box':
xpos = key+(0,)
q1, q2, q3 = (np.percentile(values, q=q)
Expand Down
7 changes: 7 additions & 0 deletions holoviews/tests/plotting/bokeh/testviolinplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def test_violin_empty(self):
self.assertEqual(patch_source.data['xs'], [[]])
self.assertEqual(patch_source.data['ys'], [np.array([])])

def test_violin_single_point(self):
data = {'x': [1], 'y': [1]}
violin = Violin(data=data, kdims='x', vdims='y').opts(plot=dict(inner='box'))

plot = bokeh_renderer.get_plot(violin)
self.assertEqual(plot.handles['x_range'].factors, ['1'])

###########################
# Styling mapping #
###########################
Expand Down