From 208204103a1530545286032828e479f8a54d0c5c Mon Sep 17 00:00:00 2001 From: ahuang11 Date: Thu, 21 Feb 2019 20:25:13 -0800 Subject: [PATCH] Add clabel param --- holoviews/plotting/bokeh/element.py | 6 ++++++ holoviews/plotting/mpl/element.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py index 70cd95c813..d414377d2b 100644 --- a/holoviews/plotting/bokeh/element.py +++ b/holoviews/plotting/bokeh/element.py @@ -1336,6 +1336,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.""") @@ -1390,6 +1394,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'], **self._colorbar_defaults) color_bar = ColorBar(color_mapper=color_mapper, ticker=ticker, **dict(opts, **self.colorbar_opts)) diff --git a/holoviews/plotting/mpl/element.py b/holoviews/plotting/mpl/element.py index 1ab618900e..e6ce085e74 100644 --- a/holoviews/plotting/mpl/element.py +++ b/holoviews/plotting/mpl/element.py @@ -643,6 +643,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.""") @@ -737,7 +741,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