From d0e75c2a9141d28a13cae1bb8417c1a2e8583704 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 28 Mar 2018 14:04:58 +0100 Subject: [PATCH] Added ColorbarPlot tests --- tests/plotting/bokeh/testelementplot.py | 29 +++++++++++++++++ tests/plotting/matplotlib/testelementplot.py | 34 ++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 tests/plotting/matplotlib/testelementplot.py diff --git a/tests/plotting/bokeh/testelementplot.py b/tests/plotting/bokeh/testelementplot.py index b96b3202f1..814e9d5a56 100644 --- a/tests/plotting/bokeh/testelementplot.py +++ b/tests/plotting/bokeh/testelementplot.py @@ -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') diff --git a/tests/plotting/matplotlib/testelementplot.py b/tests/plotting/matplotlib/testelementplot.py new file mode 100644 index 0000000000..6608a67413 --- /dev/null +++ b/tests/plotting/matplotlib/testelementplot.py @@ -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))