diff --git a/holoviews/plotting/bokeh/stats.py b/holoviews/plotting/bokeh/stats.py index db042c15e1..967010a5b6 100644 --- a/holoviews/plotting/bokeh/stats.py +++ b/holoviews/plotting/bokeh/stats.py @@ -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) diff --git a/holoviews/tests/plotting/bokeh/testviolinplot.py b/holoviews/tests/plotting/bokeh/testviolinplot.py index 31efd20470..a2a1b8d55b 100644 --- a/holoviews/tests/plotting/bokeh/testviolinplot.py +++ b/holoviews/tests/plotting/bokeh/testviolinplot.py @@ -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 # ###########################