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):