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

Fixed hover bug when plotting on inverted axis #4010

Merged
merged 2 commits into from
Oct 1, 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
5 changes: 3 additions & 2 deletions holoviews/plotting/bokeh/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -166,13 +166,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)
Expand Down
10 changes: 5 additions & 5 deletions holoviews/tests/plotting/bokeh/testrasterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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))
Expand All @@ -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])