From fdc6115f2fe74ad9bc1df16029d5763a7d7225a6 Mon Sep 17 00:00:00 2001 From: ahuang11 Date: Fri, 11 Jan 2019 21:16:50 -0800 Subject: [PATCH 1/2] Add colorbar lim option --- holoviews/plotting/bokeh/element.py | 9 ++++++++- holoviews/plotting/mpl/element.py | 8 ++++++++ holoviews/plotting/plot.py | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py index 6f8ca842ac..189c7bfbb9 100644 --- a/holoviews/plotting/bokeh/element.py +++ b/holoviews/plotting/bokeh/element.py @@ -1324,6 +1324,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.""") + 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.""") + colorbar = param.Boolean(default=False, doc=""" Whether to display a colorbar.""") @@ -1405,7 +1409,10 @@ def _get_colormapper(self, eldim, element, ranges, style, factors=None, colors=N ncolors = None if factors is None else len(factors) if eldim: - if dim_name in ranges: + # check if there's an actual value (not np.nan) + if sum((~np.isnan(v) for v in self.clim)): + low, high = self.clim + elif dim_name in ranges: low, high = ranges[dim_name]['combined'] elif isinstance(eldim, dim): low, high = np.nan, np.nan diff --git a/holoviews/plotting/mpl/element.py b/holoviews/plotting/mpl/element.py index 06233c9e6d..d59cf57fa1 100644 --- a/holoviews/plotting/mpl/element.py +++ b/holoviews/plotting/mpl/element.py @@ -631,6 +631,9 @@ def teardown_handles(self): class ColorbarPlot(ElementPlot): + 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.""") colorbar = param.Boolean(default=False, doc=""" Whether to draw a colorbar.""") @@ -775,6 +778,11 @@ def _norm_kwargs(self, element, ranges, opts, vdim, values=None, prefix=''): self.handles[prefix+'color_dim'] = vdim clim = opts.pop(prefix+'clims', None) + + # check if there's an actual value (not np.nan) + if clim is None and sum((~np.isnan(v) for v in self.clim)): + clim = self.clim + if clim is None: if not len(values): clim = (0, 0) diff --git a/holoviews/plotting/plot.py b/holoviews/plotting/plot.py index 5bfa6a45b2..91b57b5175 100644 --- a/holoviews/plotting/plot.py +++ b/holoviews/plotting/plot.py @@ -137,6 +137,7 @@ def _define_interface(self, plots, allow_mismatch): if ((v.precedence is None) or (v.precedence >= 0))} for plot in plots] param_sets = [set(params.keys()) for params in parameters] + if not allow_mismatch and not all(pset == param_sets[0] for pset in param_sets): raise Exception("All selectable plot classes must have identical plot options.") styles= [plot.style_opts for plot in plots] From f26cd3d722a3b69f2b2e0cfac180f0a26955548c Mon Sep 17 00:00:00 2001 From: ahuang11 Date: Fri, 11 Jan 2019 21:17:55 -0800 Subject: [PATCH 2/2] Remove extra line --- holoviews/plotting/plot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/holoviews/plotting/plot.py b/holoviews/plotting/plot.py index 91b57b5175..5bfa6a45b2 100644 --- a/holoviews/plotting/plot.py +++ b/holoviews/plotting/plot.py @@ -137,7 +137,6 @@ def _define_interface(self, plots, allow_mismatch): if ((v.precedence is None) or (v.precedence >= 0))} for plot in plots] param_sets = [set(params.keys()) for params in parameters] - if not allow_mismatch and not all(pset == param_sets[0] for pset in param_sets): raise Exception("All selectable plot classes must have identical plot options.") styles= [plot.style_opts for plot in plots]