From 4a9e60990bd287e0f39b24d569f65b1ae459d4a0 Mon Sep 17 00:00:00 2001 From: Andrew <15331990+ahuang11@users.noreply.github.com> Date: Tue, 29 Oct 2024 08:52:34 -0700 Subject: [PATCH] Fix bar width for small xdiff (#6428) --- holoviews/plotting/bokeh/chart.py | 2 +- holoviews/tests/plotting/bokeh/test_barplot.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/bokeh/chart.py b/holoviews/plotting/bokeh/chart.py index dd76fcc68d..340a4aeed9 100644 --- a/holoviews/plotting/bokeh/chart.py +++ b/holoviews/plotting/bokeh/chart.py @@ -931,7 +931,7 @@ def get_data(self, element, ranges, style): if is_dt: width *= xdiff.astype('timedelta64[ms]').astype(np.int64) else: - width /= xdiff + width = width * xdiff if np.min(xdiff) < 1 else width / xdiff width = np.min(width) else: grouped = element.groupby(group_dim, group_type=Dataset, diff --git a/holoviews/tests/plotting/bokeh/test_barplot.py b/holoviews/tests/plotting/bokeh/test_barplot.py index 777d81826b..de52079880 100644 --- a/holoviews/tests/plotting/bokeh/test_barplot.py +++ b/holoviews/tests/plotting/bokeh/test_barplot.py @@ -391,3 +391,10 @@ def test_bar_stacked_stack_variable_sorted(self): bars = Bars(df, kdims=["a", "b"], vdims=["c"]).opts(stacked=True) plot = bokeh_renderer.get_plot(bars) assert plot.handles["glyph"].width == 0.8 + + def test_bar_narrow_non_monotonous_xvals(self): + # Tests regression: https://github.com/holoviz/hvplot/issues/1450 + dic = {"ratio": [0.82, 1.11, 3, 6], "count": [1, 2, 1, 3]} + bars = Bars(dic, kdims=["ratio"], vdims=["count"]) + plot = bokeh_renderer.get_plot(bars) + assert np.isclose(plot.handles["glyph"].width, 0.232)