Skip to content

Commit

Permalink
Merge ce5c4bc into 9c5b90b
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jul 25, 2019
2 parents 9c5b90b + ce5c4bc commit 5e7ef8b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 4 additions & 3 deletions holoviews/plotting/bokeh/element.py
Expand Up @@ -1030,12 +1030,11 @@ def _apply_transforms(self, element, data, ranges, style, group=None):
else:
factors = util.unique_array(val)
kwargs['factors'] = factors
if factors is not None and getattr(self, 'show_legend', False):
new_style['legend'] = key
cmapper = self._get_colormapper(v, element, ranges,
dict(style), name=k+'_color_mapper',
group=group, **kwargs)
if isinstance(cmapper, CategoricalColorMapper) and val.dtype.kind in 'ifMu':
categorical = isinstance(cmapper, CategoricalColorMapper)
if categorical and val.dtype.kind in 'ifMu':
if v.dimension in element:
formatter = element.get_dimension(v.dimension).pprint_value
else:
Expand All @@ -1044,6 +1043,8 @@ def _apply_transforms(self, element, data, ranges, style, group=None):
data[k+'_str__'] = [formatter(d) for d in val]
else:
field = k
if categorical and getattr(self, 'show_legend', False):
new_style['legend'] = field
key = {'field': field, 'transform': cmapper}
new_style[k] = key

Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/bokeh/path.py
Expand Up @@ -15,7 +15,7 @@
from .util import bokeh_version, multi_polygons_data


class PathPlot(ColorbarPlot):
class PathPlot(LegendPlot, ColorbarPlot):

show_legend = param.Boolean(default=False, doc="""
Whether to show legend for the plot.""")
Expand Down Expand Up @@ -143,7 +143,7 @@ def get_batched_data(self, element, ranges=None):
return data, elmapping, style


class ContourPlot(LegendPlot, PathPlot):
class ContourPlot(PathPlot):

show_legend = param.Boolean(default=False, doc="""
Whether to show legend for the plot.""")
Expand Down
17 changes: 17 additions & 0 deletions holoviews/tests/plotting/bokeh/testpathplot.py
Expand Up @@ -168,6 +168,23 @@ def test_path_continuously_varying_line_width_op(self):
self.assertEqual(source.data['ys'], [np.array([4, 3]), np.array([3, 2]), np.array([2, 1])])
self.assertEqual(source.data['line_width'], np.array([1, 7, 3]))

def test_path_continuously_varying_color_legend(self):
data = {
"x": [1,2,3,4,5,6,7,8,9],
"y": [1,2,3,4,5,6,7,8,9],
"cat": [0,1,2,0,1,2,0,1,2]
}

colors = ["#FF0000", "#00FF00", "#0000FF"]
levels=[0,1,2,3]

path = Path(data, vdims="cat").opts(color="cat", cmap=dict(zip(levels, colors)), line_width=4, show_legend=True)
plot = bokeh_renderer.get_plot(path)
item = plot.state.legend[0].items[0]
self.assertEqual(item.label, 'color_str__')
self.assertEqual(item.renderers, [plot.handles['glyph_renderer']])



class TestPolygonPlot(TestBokehPlot):

Expand Down

0 comments on commit 5e7ef8b

Please sign in to comment.