Skip to content

Commit

Permalink
Merge pull request #1014 from ioam/bokeh_bool_image
Browse files Browse the repository at this point in the history
Added support for boolean arrays in bokeh ImagePlot
  • Loading branch information
jlstevens committed Dec 11, 2016
2 parents cb23e47 + 78dc8ab commit 46b2733
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ def _get_colormapper(self, dim, element, ranges, style):
else:
return None
colors = self.clipping_colors
if isinstance(low, (bool, np.bool_)): low = int(low)
if isinstance(high, (bool, np.bool_)): high = int(high)
opts = {'low': low, 'high': high}
color_opts = [('NaN', 'nan_color'), ('max', 'high_color'), ('min', 'low_color')]
for name, opt in color_opts:
Expand Down
6 changes: 6 additions & 0 deletions holoviews/plotting/bokeh/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def get_data(self, element, ranges=None, empty=False):
if type(element) is Raster:
b = t

if img.dtype.kind == 'b':
img = img.astype(np.int8)

mapping = dict(image='image', x='x', y='y', dw='dw', dh='dh')
if empty:
data = dict(image=[], x=[], y=[], dw=[], dh=[])
Expand All @@ -57,6 +60,9 @@ class ImagePlot(RasterPlot):

def get_data(self, element, ranges=None, empty=False):
img = element.dimension_values(2, flat=False)
if img.dtype.kind == 'b':
img = img.astype(np.int8)

l, b, r, t = element.bounds.lbrt()
dh, dw = t-b, r-l
mapping = dict(image='image', x='x', y='y', dw='dw', dh='dh')
Expand Down
9 changes: 9 additions & 0 deletions tests/testplotinstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ def test_bars_suppress_legend(self):
fig = plot.state
assert len(fig.legend[0].items) == 0

def test_image_boolean_array(self):
img = Image(np.array([[True, False], [False, True]]))
plot = bokeh_renderer.get_plot(img)
cmapper = plot.handles['color_mapper']
source = plot.handles['source']
self.assertEqual(cmapper.low, 0)
self.assertEqual(cmapper.high, 1)
self.assertEqual(source.data['image'][0],
np.array([[0, 1], [1, 0]]))

class TestPlotlyPlotInstantiation(ComparisonTestCase):

Expand Down

0 comments on commit 46b2733

Please sign in to comment.