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

Histogram improvements #1836

merged 15 commits into from Oct 31, 2017
Diff settings


Just for now

Fixed histogram operation range calculation

  • Loading branch information...
Philipp Rudiger Philipp Rudiger
Philipp Rudiger authored and Philipp Rudiger committed Oct 31, 2017
commit 7330999624063871a573d4d244a27e0f88c34cd9
Copy path View file
@@ -12,7 +12,8 @@
from ..core import (Operation, NdOverlay, Overlay, GridMatrix,
HoloMap, Dataset, Element, Collator, Dimension)
from import ArrayInterface, DictInterface
from ..core.util import find_minmax, group_sanitizer, label_sanitizer, pd, basestring
from ..core.util import (find_minmax, group_sanitizer, label_sanitizer, pd,
basestring, datetime_types)
from ..element.chart import Histogram, Scatter
from ..element.raster import Raster, Image, RGB, QuadMesh
from ..element.path import Contours, Polygons
@@ -498,13 +499,13 @@ class histogram(Operation):
mean_weighted = param.Boolean(default=False, doc="""
Whether the weighted frequencies are averaged.""")

normed = param.ObjectSelector(default=True,
normed = param.ObjectSelector(default=True,
objects=[True, False, 'integral', 'height'],
Controls normalization behavior. If `True` or `'integral'`, then
Controls normalization behavior. If `True` or `'integral'`, then
`density=True` is passed to np.histogram, and the distribution
is normalized such that the integral is unity. If `False`,
then the frequencies will be raw counts. If `'height'`, then the
is normalized such that the integral is unity. If `False`,
then the frequencies will be raw counts. If `'height'`, then the
frequencies are normalized such that the max bin height is unity.""")

nonzero = param.Boolean(default=False, doc="""
@@ -541,16 +542,12 @@ def _process(self, view, key=None):
weights = weights[mask]
weights = None
hist_range = find_minmax((np.nanmin(data), np.nanmax(data)), (0, -float('inf')))\
if self.p.bin_range is None else self.p.bin_range
except ValueError:
hist_range = (0, 1)

data = data[np.isfinite(data)]
hist_range = self.p.bin_range or view.range(selected_dim)
# Avoids range issues including zero bin range and empty bins
if hist_range == (0, 0):
if hist_range == (0, 0) or any(not np.isfinite(r) for r in hist_range):
hist_range = (0, 1)
data = data[np.invert(np.isnan(data))]
if self.p.log:
bin_min = max([abs(hist_range[0]), data[data>0].min()])
edges = np.logspace(np.log10(bin_min), np.log10(hist_range[1]),
@@ -559,12 +556,11 @@ def _process(self, view, key=None):
edges = np.linspace(hist_range[0], hist_range[1], self.p.num_bins + 1)
normed = False if self.p.mean_weighted and self.p.weight_dimension else self.p.normed

data = data[np.isfinite(data)]
if len(data):
if normed:
if normed:
# This covers True, 'height', 'integral'
hist, edges = np.histogram(data[np.isfinite(data)], density=True,
range=hist_range, weights=weights, bins=edges)
hist, edges = np.histogram(data, density=True, range=hist_range,
weights=weights, bins=edges)
if normed=='height':
hist /= hist.max()
@@ -786,8 +782,9 @@ def _process(self, p, element, ranges={}):
el_data =

# Get dimensions to plot against each other
types = (str, basestring)+datetime_types
dims = [d for d in element.dimensions()
if _is_number(element.range(d)[0])]
if not isinstance(element.range(d)[0], types)]
permuted_dims = [(d1, d2) for d1 in dims
for d2 in dims[::-1]]

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.