Skip to content

Commit

Permalink
Fixed categorical coloring of Contours in matplotlib (#2259)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 9, 2018
1 parent 73d547c commit b6da56f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion holoviews/core/data/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,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)
Expand Down
7 changes: 5 additions & 2 deletions holoviews/plotting/mpl/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}
Expand Down
9 changes: 9 additions & 0 deletions tests/testplotinstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit b6da56f

Please sign in to comment.