From 23c4ccf3d9608dac6e2eec21f196a1ead136eaec Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Sun, 14 Jan 2018 23:14:59 +0000
Subject: [PATCH 1/2] Fixed categorical coloring of Contours in matplotlib
---
holoviews/plotting/mpl/path.py | 7 +++++--
tests/testplotinstantiation.py | 9 +++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/holoviews/plotting/mpl/path.py b/holoviews/plotting/mpl/path.py
index 0be0fb855c..33757a515c 100644
--- a/holoviews/plotting/mpl/path.py
+++ b/holoviews/plotting/mpl/path.py
@@ -85,9 +85,12 @@ def get_data(self, element, ranges, style):
return (paths,), style, {}
if element.level is not None:
- style['array'] = np.full(len(paths), element.level)
+ array = np.full(len(paths), element.level)
else:
- style['array'] = element.dimension_values(cdim, expanded=False)
+ array = element.dimension_values(cdim, expanded=False)
+ if array.dtype.kind not in 'if':
+ array = np.searchsorted(np.unique(array), array)
+ style['array']= array
self._norm_kwargs(element, ranges, style, cdim)
style['clim'] = style.pop('vmin'), style.pop('vmax')
return (paths,), style, {}
diff --git a/tests/testplotinstantiation.py b/tests/testplotinstantiation.py
index 29ab27d5b3..b76adcd813 100644
--- a/tests/testplotinstantiation.py
+++ b/tests/testplotinstantiation.py
@@ -341,6 +341,15 @@ def test_image_listed_cmap(self):
self.assertIsInstance(cmap, ListedColormap)
self.assertEqual(cmap.colors, colors)
+ def test_contours_categorical_color(self):
+ path = Contours([{('x', 'y'): np.random.rand(10, 2), 'z': cat}
+ for cat in ('B', 'A', 'B')],
+ vdims='z').opts(plot=dict(color_index='z'))
+ plot = mpl_renderer.get_plot(path)
+ artist = plot.handles['artist']
+ self.assertEqual(artist.get_array(), np.array([1, 0, 1]))
+
+
class TestBokehPlotInstantiation(ComparisonTestCase):
From 921752a4f50c4862d6b0ae4c50c5ba508539936a Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Sun, 4 Feb 2018 15:56:56 +0000
Subject: [PATCH 2/2] Fixed issue generating string arrays
---
holoviews/core/data/dictionary.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/holoviews/core/data/dictionary.py b/holoviews/core/data/dictionary.py
index b8ae1d0093..e0f9e827d0 100644
--- a/holoviews/core/data/dictionary.py
+++ b/holoviews/core/data/dictionary.py
@@ -213,7 +213,7 @@ def values(cls, dataset, dim, expanded=True, flat=True):
if np.isscalar(values):
if not expanded:
return np.array([values])
- values = np.full(len(dataset), values)
+ values = np.full(len(dataset), values, dtype=np.array(values).dtype)
else:
if not expanded:
return util.unique_array(values)