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

Added log option to histogram operation #929

Merged
merged 3 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 10 additions & 2 deletions holoviews/operation/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ class histogram(ElementOperation):
individually = param.Boolean(default=True, doc="""
Specifies whether the histogram will be rescaled for each Raster in a UniformNdMapping.""")

log = param.Boolean(default=False, doc="""
Whether to use base 10 logarithmic samples for the bin edges.""")

mean_weighted = param.Boolean(default=False, doc="""
Whether the weighted frequencies are averaged.""")

Expand Down Expand Up @@ -518,16 +521,21 @@ def _process(self, view, key=None):
if hist_range == (0, 0):
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]),
self.p.num_bins+1)
else:
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
try:
hist, edges = np.histogram(data[np.isfinite(data)], normed=normed,
range=hist_range, weights=weights, bins=self.p.num_bins)
range=hist_range, weights=weights, bins=edges)
if not normed and self.p.weight_dimension and self.p.mean_weighted:
hist_mean, _ = np.histogram(data[np.isfinite(data)], normed=normed,
range=hist_range, bins=self.p.num_bins)
hist /= hist_mean
except:
edges = np.linspace(hist_range[0], hist_range[1], self.p.num_bins + 1)
hist = np.zeros(self.p.num_bins)

hist[np.isnan(hist)] = 0
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class SideHistogramPlot(ColorbarPlot, HistogramPlot):

def get_data(self, element, ranges=None, empty=None):
if self.invert_axes:
mapping = dict(top='left', bottom='right', left=0, right='top')
mapping = dict(top='right', bottom='left', left=0, right='top')
else:
mapping = dict(top='top', bottom=0, left='left', right='right')

Expand Down