From aa8504fb2e03debff9e435098acfef39b30de30a Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 1 Oct 2019 22:44:01 +0200 Subject: [PATCH] Fixed hover bug when plotting on inverted axis (#4010) --- holoviews/plotting/bokeh/raster.py | 5 +++-- holoviews/tests/plotting/bokeh/testrasterplot.py | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/holoviews/plotting/bokeh/raster.py b/holoviews/plotting/bokeh/raster.py index 3c90573a25..fc6ff444c6 100644 --- a/holoviews/plotting/bokeh/raster.py +++ b/holoviews/plotting/bokeh/raster.py @@ -89,11 +89,11 @@ def get_data(self, element, ranges, style): if self.invert_axes: l, b, r, t = b, l, t, r + dh, dw = t-b, r-l if self.invert_xaxis: l, r = r, l if self.invert_yaxis: b, t = t, b - dh, dw = t-b, r-l data = dict(x=[l], y=[b], dw=[dw], dh=[dh]) for i, vdim in enumerate(element.vdims, 2): @@ -164,13 +164,14 @@ def get_data(self, element, ranges, style): if self.invert_axes: img = img.T l, b, r, t = b, l, t, r + + dh, dw = t-b, r-l if self.invert_xaxis: l, r = r, l img = img[:, ::-1] if self.invert_yaxis: img = img[::-1] b, t = t, b - dh, dw = t-b, r-l if 0 in img.shape: img = np.zeros((1, 1), dtype=np.uint32) diff --git a/holoviews/tests/plotting/bokeh/testrasterplot.py b/holoviews/tests/plotting/bokeh/testrasterplot.py index 90a58eb21a..b04a624ffc 100644 --- a/holoviews/tests/plotting/bokeh/testrasterplot.py +++ b/holoviews/tests/plotting/bokeh/testrasterplot.py @@ -30,7 +30,7 @@ def test_raster_invert_axes(self): self.assertEqual(source.data['x'][0], 0) self.assertEqual(source.data['y'][0], 3) self.assertEqual(source.data['dw'][0], 2) - self.assertEqual(source.data['dh'][0], -3) + self.assertEqual(source.data['dh'][0], 3) def test_image_invert_axes(self): arr = np.array([[0, 1, 2], [3, 4, 5]]) @@ -54,7 +54,7 @@ def test_image_invert_xaxis(self): self.assertEqual(cdata['x'], [0.5]) self.assertEqual(cdata['y'], [-0.5]) self.assertEqual(cdata['dh'], [1.0]) - self.assertEqual(cdata['dw'], [-1.0]) + self.assertEqual(cdata['dw'], [1.0]) self.assertEqual(cdata['image'][0], arr[::-1, ::-1]) def test_image_invert_yaxis(self): @@ -67,7 +67,7 @@ def test_image_invert_yaxis(self): cdata = plot.handles['source'].data self.assertEqual(cdata['x'], [-0.5]) self.assertEqual(cdata['y'], [0.5]) - self.assertEqual(cdata['dh'], [-1.0]) + self.assertEqual(cdata['dh'], [1.0]) self.assertEqual(cdata['dw'], [1.0]) self.assertEqual(cdata['image'][0], arr) @@ -81,7 +81,7 @@ def test_rgb_invert_xaxis(self): self.assertEqual(cdata['x'], [0.5]) self.assertEqual(cdata['y'], [-0.5]) self.assertEqual(cdata['dh'], [1.0]) - self.assertEqual(cdata['dw'], [-1.0]) + self.assertEqual(cdata['dw'], [1.0]) def test_rgb_invert_yaxis(self): rgb = RGB(np.random.rand(10, 10, 3)).opts(plot=dict(invert_yaxis=True)) @@ -92,5 +92,5 @@ def test_rgb_invert_yaxis(self): cdata = plot.handles['source'].data self.assertEqual(cdata['x'], [-0.5]) self.assertEqual(cdata['y'], [0.5]) - self.assertEqual(cdata['dh'], [-1.0]) + self.assertEqual(cdata['dh'], [1.0]) self.assertEqual(cdata['dw'], [1.0])