Skip to content

Commit

Permalink
Added ColorbarPlot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 28, 2018
1 parent 74121fe commit d0e75c2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/plotting/bokeh/testelementplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,32 @@ def formatter(x):
plot = bokeh_renderer.get_plot(curve).state
self.assertIsInstance(plot.yaxis[0].formatter, FuncTickFormatter)



class TestColorbarPlot(TestBokehPlot):

def test_colormapper_symmetric(self):
img = Image(np.array([[0, 1], [2, 3]])).options(symmetric=True)
plot = bokeh_renderer.get_plot(img)
cmapper = plot.handles['color_mapper']
self.assertEqual(cmapper.low, -3)
self.assertEqual(cmapper.high, 3)

def test_colormapper_color_levels(self):
img = Image(np.array([[0, 1], [2, 3]])).options(color_levels=5)
plot = bokeh_renderer.get_plot(img)
cmapper = plot.handles['color_mapper']
self.assertEqual(len(cmapper.palette), 5)

def test_colormapper_transparent_nan(self):
img = Image(np.array([[0, 1], [2, 3]])).options(clipping_colors={'NaN': 'transparent'})
plot = bokeh_renderer.get_plot(img)
cmapper = plot.handles['color_mapper']
self.assertEqual(cmapper.nan_color, 'rgba(0, 0, 0, 0)')

def test_colormapper_min_max_colors(self):
img = Image(np.array([[0, 1], [2, 3]])).options(clipping_colors={'min': 'red', 'max': 'blue'})
plot = bokeh_renderer.get_plot(img)
cmapper = plot.handles['color_mapper']
self.assertEqual(cmapper.low_color, 'red')
self.assertEqual(cmapper.high_color, 'blue')
34 changes: 34 additions & 0 deletions tests/plotting/matplotlib/testelementplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import numpy as np

from holoviews.element import Image

from .testplot import TestMPLPlot, mpl_renderer


class TestColorbarPlot(TestMPLPlot):

def test_colormapper_symmetric(self):
img = Image(np.array([[0, 1], [2, 3]])).options(symmetric=True)
plot = mpl_renderer.get_plot(img)
artist = plot.handles['artist']
self.assertEqual(artist.get_clim(), (-3, 3))

def test_colormapper_color_levels(self):
img = Image(np.array([[0, 1], [2, 3]])).options(color_levels=5)
plot = mpl_renderer.get_plot(img)
artist = plot.handles['artist']
self.assertEqual(len(artist.cmap.colors), 5)

def test_colormapper_transparent_nan(self):
img = Image(np.array([[0, 1], [2, 3]])).options(clipping_colors={'NaN': 'transparent'})
plot = mpl_renderer.get_plot(img)
cmap = plot.handles['artist'].cmap
self.assertEqual(cmap._rgba_bad, (1.0, 1.0, 1.0, 0))

def test_colormapper_min_max_colors(self):
img = Image(np.array([[0, 1], [2, 3]])).options(clipping_colors={'min': 'red', 'max': 'blue'})
plot = mpl_renderer.get_plot(img)
cmap = plot.handles['artist'].cmap
print(dir(cmap))
self.assertEqual(cmap._rgba_under, (1.0, 0, 0, 1))
self.assertEqual(cmap._rgba_over, (0, 0, 1.0, 1))

0 comments on commit d0e75c2

Please sign in to comment.