Skip to content

Commit

Permalink
Fix coloring of SideHistogram in bokeh (#4458)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 9, 2020
1 parent bdd4a2d commit fb8c426
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
15 changes: 10 additions & 5 deletions holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,16 @@ def get_data(self, element, ranges, style):
data, mapping, style = HistogramPlot.get_data(self, element, ranges, style)
color_dims = [d for d in self.adjoined.traverse(lambda x: x.handles.get('color_dim'))
if d is not None]
dim = color_dims[0] if color_dims else None
cmapper = self._get_colormapper(dim, element, {}, {})
if cmapper and dim in element.dimensions():
data[dim.name] = [] if self.static_source else element.dimension_values(dim)
mapping['fill_color'] = {'field': dim.name,
dimension = color_dims[0] if color_dims else None
cmapper = self._get_colormapper(dimension, element, {}, {})
if cmapper and dimension in element.dimensions():
if isinstance(dimension, dim):
dim_name = dimension.dimension.name
data[dim_name] = [] if self.static_source else dimension.apply(element)
else:
dim_name = dimension.name
data[dim_name] = [] if self.static_source else element.dimension_values(dimension)
mapping['fill_color'] = {'field': dim_name,
'transform': cmapper}
return (data, mapping, style)

Expand Down
19 changes: 13 additions & 6 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

from bokeh.core.properties import value
from bokeh.document.events import ModelChangedEvent
from bokeh.models import Renderer, Title, Legend, ColorBar, tools
from bokeh.models import (
ColorBar, ColorMapper, Legend, Renderer, Title, tools
)
from bokeh.models.axes import CategoricalAxis, DatetimeAxis
from bokeh.models.formatters import (
FuncTickFormatter, TickFormatter, MercatorTickFormatter
Expand Down Expand Up @@ -1720,12 +1722,17 @@ def _get_colormapper(self, eldim, element, ranges, style, factors=None, colors=N

# Attempt to find matching colormapper on the adjoined plot
if self.adjoined:
cmapper_name = dim_name+name
cmappers = self.adjoined.traverse(lambda x: (x.handles.get('color_dim'),
x.handles.get(name, x.handles.get(cmapper_name))))
cmappers = [cmap for cdim, cmap in cmappers if cdim == eldim]
cmappers = self.adjoined.traverse(
lambda x: (x.handles.get('color_dim'),
x.handles.get(name),
[v for v in x.handles.values()
if isinstance(v, ColorMapper)])
)
cmappers = [(cmap, mappers) for cdim, cmap, mappers in cmappers
if cdim == eldim]
if cmappers:
cmapper = cmappers[0]
cmapper, mappers = cmappers[0]
cmapper = cmapper if cmapper else mappers[0]

This comment has been minimized.

Copy link
@rafiyr

rafiyr Mar 24, 2021

Contributor

I'm seeing exceptions from this line. Should it check if mappers is not empty or should something else have caught that earlier?

This comment has been minimized.

Copy link
@philippjfr

philippjfr Mar 29, 2021

Author Member

I think checking that it's not empty is right.

This comment has been minimized.

Copy link
@rafiyr

rafiyr via email Apr 7, 2021

Contributor
self.handles['color_mapper'] = cmapper
return cmapper
else:
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/mpl/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PathPlot(ColorbarPlot):
style_opts = ['alpha', 'color', 'linestyle', 'linewidth', 'visible', 'cmap']

def get_data(self, element, ranges, style):
cdim = element.get_dimension(self.color_index or style.get('color'))
cdim = element.get_dimension(self.color_index)

with abbreviated_exception():
style = self._apply_transforms(element, ranges, style)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def _compute_group_range(cls, group, elements, ranges, framewise, top_level):
dim_name = repr(v)
if dim_name in prev_ranges and not framewise:
continue
values = v.apply(el, expanded=False, all_values=True)
values = v.apply(el, all_values=True)

This comment has been minimized.

Copy link
@philippjfr

philippjfr Apr 21, 2021

Author Member

Not sure about this honestly, I think this will break Polygons. Will have to take a look.

factors = None
if values.dtype.kind == 'M':
drange = values.min(), values.max()
Expand Down

0 comments on commit fb8c426

Please sign in to comment.