Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement clim_percentile for RGB #6137

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions holoviews/plotting/bokeh/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ class RGBPlot(LegendPlot):

padding = param.ClassSelector(default=0, class_=(int, float, tuple))

clim_percentile = param.ClassSelector(default=False, class_=(int, float, bool), doc="""
Percentile value to compute colorscale robust to outliers. If
True, uses 2nd and 98th percentile; otherwise uses the specified
numerical percentile value.""")

style_opts = ['alpha'] + base_properties

_nonvectorized_styles = style_opts
Expand Down Expand Up @@ -181,6 +186,14 @@ def get_data(self, element, ranges, style):
img = np.dstack([element.dimension_values(d, flat=False)
for d in element.vdims])

if self.clim_percentile:
if isinstance(self.clim_percentile, (int, float)):
low, high = np.percentile(img, (self.clim_percentile, 100 - self.clim_percentile))
else: # True
low, high = np.percentile(img, (2, 98))
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
img = np.clip(img, low, high)
img = img / img.max((0, 1)) * 255
ahuang11 marked this conversation as resolved.
Show resolved Hide resolved

nan_mask = np.isnan(img)
img[nan_mask] = 0

Expand Down
Loading