Skip to content

Commit

Permalink
Add clabel param (#3517)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored and jlstevens committed Mar 27, 2019
1 parent 5a3c3df commit ff56900
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,10 @@ class ColorbarPlot(ElementPlot):
Number of discrete colors to use when colormapping or a set of color
intervals defining the range of values to map each color to.""")

clabel = param.String(default=None, doc="""
An explicit override of the color bar label, if set takes precedence
over the title key in colorbar_opts.""")

clim = param.NumericTuple(default=(np.nan, np.nan), length=2, doc="""
User-specified colorbar axis range limits for the plot, as a tuple (low,high).
If specified, takes precedence over data and dimension ranges.""")
Expand Down Expand Up @@ -1569,6 +1573,8 @@ def _draw_colorbar(self, plot, color_mapper, prefix=''):
if any(isinstance(model, ColorBar) for model in getattr(plot, pos, [])):
return

if self.clabel:
self.colorbar_opts.update({'title': self.clabel})
opts = dict(cbar_opts['opts'], color_mapper=color_mapper, ticker=ticker,
**self._colorbar_defaults)
color_bar = ColorBar(**dict(opts, **self.colorbar_opts))
Expand Down
8 changes: 7 additions & 1 deletion holoviews/plotting/mpl/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,10 @@ def teardown_handles(self):

class ColorbarPlot(ElementPlot):

clabel = param.String(default=None, doc="""
An explicit override of the color bar label, if set takes precedence
over the title key in colorbar_opts.""")

clim = param.NumericTuple(default=(np.nan, np.nan), length=2, doc="""
User-specified colorbar axis range limits for the plot, as a tuple (low,high).
If specified, takes precedence over data and dimension ranges.""")
Expand Down Expand Up @@ -746,7 +750,9 @@ def _draw_colorbar(self, element=None, dimension=None, redraw=True):
if isinstance(dimension, dim):
dimension = dimension.dimension
dimension = element.get_dimension(dimension)
if dimension:
if self.clabel:
label = self.clabel
elif dimension:
label = dimension.pprint_label
elif element.vdims:
label = element.vdims[0].pprint_label
Expand Down

0 comments on commit ff56900

Please sign in to comment.