Add extend for plot
@@ -695,6 +695,11 @@ class ColorbarPlot(ElementPlot):
cbar_width = param.Number(default=0.05, doc="""
Width of the colorbar as a fraction of the main plot""")
+ cbar_extend = param.ObjectSelector(
+ objects=['neither', 'both', 'min', 'max'], default=None, doc="""
+ If not 'neither', make pointed end(s) for out-of- range values."""
+ )
+
symmetric = param.Boolean(default=False, doc="""
Whether to make the colormap symmetric around zero.""")
@@ -704,7 +709,6 @@ class ColorbarPlot(ElementPlot):
def __init__(self, *args, **kwargs):
super(ColorbarPlot, self).__init__(*args, **kwargs)
- self._cbar_extend = 'neither'
def _adjust_cbar(self, cbar, label, dim):
noalpha = math.floor(self.style[self.cyclic_index].get('alpha', 1)) == 1
@@ -785,7 +789,7 @@ class ColorbarPlot(ElementPlot):
scaled_w = w*width
cax = fig.add_axes([l+w+padding+(scaled_w+padding+w*0.15)*offset,
b, scaled_w, h])
- cbar = fig.colorbar(artist, cax=cax, ax=axis, extend=self._cbar_extend)
+ cbar = fig.colorbar(artist, cax=cax, ax=axis, extend=self.cbar_extend)
self._set_axis_formatter(cbar.ax.yaxis, dimension, self.cformatter)
self._adjust_cbar(cbar, label, dimension)
self.handles['cax'] = cax
@@ -902,12 +906,15 @@ class ColorbarPlot(ElementPlot):
el_min, el_max = -np.inf, np.inf
vmin = -np.inf if opts[prefix+'vmin'] is None else opts[prefix+'vmin']
vmax = np.inf if opts[prefix+'vmax'] is None else opts[prefix+'vmax']
+ if self.cbar_extend is None:
if el_min < vmin and el_max > vmax:
- self._cbar_extend = 'both'
+ self.cbar_extend = 'both'
elif el_min < vmin:
- self._cbar_extend = 'min'
+ self.cbar_extend = 'min'
elif el_max > vmax:
- self._cbar_extend = 'max'
+ self.cbar_extend = 'max'
+ else:
+ self.cbar_extend = 'neither'
# Define special out-of-range colors on colormap
colors = {}
