From 466c506fb8814d608682bafb42bd3a02e36a612b Mon Sep 17 00:00:00 2001 From: Eric Blum Date: Wed, 16 Jan 2019 18:29:56 -0500 Subject: [PATCH 1/2] fix bug using 'stick' in violin plot with non-varying data --- holoviews/plotting/bokeh/stats.py | 5 ++++- holoviews/tests/plotting/bokeh/testviolinplot.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/bokeh/stats.py b/holoviews/plotting/bokeh/stats.py index db042c15e1..fde6c9742c 100644 --- a/holoviews/plotting/bokeh/stats.py +++ b/holoviews/plotting/bokeh/stats.py @@ -359,7 +359,10 @@ def _kde_data(self, el, key, **kwargs): segments['y1'].append(sy) elif self.inner == 'stick': for value in values: - sidx = np.argmin(np.abs(xs-value)) + if len(xs): + sidx = np.argmin(np.abs(xs-value)) + else: + continue sx, sy = xs[sidx], ys[sidx] segments['x'].append(sx) segments['y0'].append(key+(-sy[-1],)) 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 # ########################### From 413e334b8e79d42ee946495b052bc5b9f9a41115 Mon Sep 17 00:00:00 2001 From: Eric Blum Date: Wed, 16 Jan 2019 18:32:58 -0500 Subject: [PATCH 2/2] simplify expression for quartiles and stick in violin. --- holoviews/plotting/bokeh/stats.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/holoviews/plotting/bokeh/stats.py b/holoviews/plotting/bokeh/stats.py index fde6c9742c..967010a5b6 100644 --- a/holoviews/plotting/bokeh/stats.py +++ b/holoviews/plotting/bokeh/stats.py @@ -347,26 +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: - if len(xs): + if len(xs): + for value in values: sidx = np.argmin(np.abs(xs-value)) - else: - continue - sx, sy = xs[sidx], ys[sidx] - segments['x'].append(sx) - segments['y0'].append(key+(-sy[-1],)) - segments['y1'].append(sy) + 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)