Skip to content

Commit

Permalink
Expose rescale_discrete_levels in the Bokeh backend (#5312)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt authored May 18, 2022
1 parent e4ac7ba commit c265cc1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
with:
miniconda-version: "latest"
mamba-version: "*"
channels: pyviz/label/dev,conda-forge,nodefaults
channels: pyviz/label/dev,bokeh/label/dev,conda-forge,nodefaults
- name: Fetch unshallow
run: git fetch --prune --tags --unshallow -f
- name: Set output
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
env:
HV_REQUIREMENTS: "-o unit_tests"
MPLBACKEND: "Agg"
CHANS_DEV: "-c pyviz/label/dev -c bokeh -c conda-forge -c nodefaults"
CHANS_DEV: "-c pyviz/label/dev -c bokeh/label/dev -c conda-forge -c nodefaults"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
Expand All @@ -43,7 +43,7 @@ jobs:
conda update -n base -c defaults conda
conda config --prepend channels nodefaults
conda config --prepend channels conda-forge
conda config --prepend channels bokeh
conda config --prepend channels bokeh/label/dev
conda config --prepend channels pyviz/label/dev
conda config --remove channels defaults
conda create -n test-environment python=${{ matrix.python-version }} pyctdev
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
MAMBA_NO_BANNER: 1
HV_REQUIREMENTS: "-o unit_tests"
MPLBACKEND: "Agg"
CHANS_DEV: "-c pyviz/label/dev -c bokeh -c conda-forge -c nodefaults"
CHANS_DEV: "-c pyviz/label/dev -c bokeh/label/dev -c conda-forge -c nodefaults"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
Expand All @@ -113,7 +113,7 @@ jobs:
with:
miniconda-version: "latest"
mamba-version: "*"
channels: pyviz/label/dev,bokeh,conda-forge,nodefaults
channels: pyviz/label/dev,bokeh/label/dev,conda-forge,nodefaults
- name: Fetch unshallow
run: git fetch --prune --tags --unshallow
- name: conda setup
Expand Down
12 changes: 11 additions & 1 deletion holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,14 @@ class ColorbarPlot(ElementPlot):
logz = param.Boolean(default=False, doc="""
Whether to apply log scaling to the z-axis.""")

rescale_discrete_levels = param.Boolean(default=True, doc="""
If ``cnorm='eq_hist`` and there are only a few discrete values,
then ``rescale_discrete_levels=True`` decreases the lower
limit of the autoranged span so that the values are rendering
towards the (more visible) top of the palette, thus
avoiding washout of the lower values. Has no effect if
``cnorm!=`eq_hist``.""")

symmetric = param.Boolean(default=False, doc="""
Whether to make the colormap symmetric around zero.""")

Expand Down Expand Up @@ -1961,6 +1969,7 @@ def _get_color_data(self, element, ranges, style, name='color', factors=None, co

def _get_cmapper_opts(self, low, high, factors, colors):
if factors is None:
opts = {}
if self.cnorm == 'linear':
colormapper = LinearColorMapper
if self.cnorm == 'log' or self.logz:
Expand All @@ -1983,14 +1992,15 @@ def _get_cmapper_opts(self, low, high, factors, colors):
"Note that the option cnorm='eq_hist' requires "
"bokeh 2.2.3 or higher.")
colormapper = EqHistColorMapper
if bokeh_version > LooseVersion('2.4.2'):
opts['rescale_discrete_levels'] = self.rescale_discrete_levels
if isinstance(low, (bool, np.bool_)): low = int(low)
if isinstance(high, (bool, np.bool_)): high = int(high)
# Pad zero-range to avoid breaking colorbar (as of bokeh 1.0.4)
if low == high:
offset = self.default_span / 2
low -= offset
high += offset
opts = {}
if util.isfinite(low):
opts['low'] = low
if util.isfinite(high):
Expand Down

0 comments on commit c265cc1

Please sign in to comment.