Skip to content

Commit

Permalink
Made clipping_color specification match between backends
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 12, 2016
1 parent eebdaad commit 4db8ea6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
20 changes: 14 additions & 6 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,12 @@ class ColorbarPlot(ElementPlot):
margin, padding, background_fill_color and more.""")

clipping_colors = param.Dict(default={}, doc="""
Dictionary to specify colors for clipped values, allows setting
color for NaN values and for values above and below the min and
max value.""")
Dictionary to specify colors for clipped values, allows
setting color for NaN values and for values above and below
the min and max value. The min, max or NaN color may specify
an RGB(A) color as a color hex string of the form #FFFFFF or
#FFFFFFFF or a length 3 or length 4 tuple specifying values in
the range 0-1 or a named HTML color.""")

logz = param.Boolean(default=False, doc="""
Whether to apply log scaling to the z-axis.""")
Expand Down Expand Up @@ -803,9 +806,14 @@ def _get_colormapper(self, dim, element, ranges, style):
return None
colors = self.clipping_colors
opts = {'low': low, 'high': high}
if 'max' in colors: opts['high_color'] = colors['max']
if 'min' in colors: opts['low_color'] = colors['min']
if 'NaN' in colors: opts['nan_color'] = colors['NaN']
color_opts = [('NaN', 'nan_color'), ('max', 'high_color'), ('min', 'low_color')]
for name, opt in color_opts:
color = colors.get(name)
if not color:
continue
elif isinstance(color, tuple):
color = [c/255. if i<3 else c for i, c in enumerate(color)]
opts[opt] = color
if 'color_mapper' in self.handles:
cmapper = self.handles['color_mapper']
cmapper.palette = palette
Expand Down
16 changes: 12 additions & 4 deletions holoviews/plotting/mpl/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,12 @@ class ColorbarPlot(ElementPlot):
Whether to draw a colorbar.""")

clipping_colors = param.Dict(default={}, doc="""
Dictionary to specify colors for clipped values, allows setting
color for NaN values and for values above and below the min and
max value.""")
Dictionary to specify colors for clipped values, allows
setting color for NaN values and for values above and below
the min and max value. The min, max or NaN color may specify
an RGB(A) color as a color hex string of the form #FFFFFF or
#FFFFFFFF or a length 3 or length 4 tuple specifying values in
the range 0-1 or a named HTML color.""")

cbar_padding = param.Number(default=0.01, doc="""
Padding between colorbar and other plots.""")
Expand Down Expand Up @@ -663,7 +666,12 @@ def _norm_kwargs(self, element, ranges, opts, vdim):
colors[k] = {'color': val[:3],
'alpha': val[3] if len(val) > 3 else 1}
elif isinstance(val, util.basestring):
colors[k] = {'color': val}
color = val
alpha = 1
if color.startswith('#') and len(color) == 9:
alpha = int(color[-2:], 16)/255.
color = color[:-2]
colors[k] = {'color': color, 'alpha': alpha}
if 'max' in colors: cmap.set_over(**colors['max'])
if 'min' in colors: cmap.set_under(**colors['min'])
if 'NaN' in colors: cmap.set_bad(**colors['NaN'])
Expand Down

0 comments on commit 4db8ea6

Please sign in to comment.