Skip to content

Commit

Permalink
Moved compositing operations into plotting utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 30, 2017
1 parent c10af53 commit 99114c0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
28 changes: 0 additions & 28 deletions holoviews/operation/stats.py
Expand Up @@ -133,31 +133,3 @@ def _process(self, element, key=None):
cntr = contours(img, filled=self.p.filled)
return cntr.clone(cntr.data[1:])
return img


class univariate_composite(Operation):

output_type = Area

def _process(self, element, key=None):
plot_opts = Store.lookup_options(Store.current_backend, element, 'plot').kwargs
bw = plot_opts.pop('bw', univariate_kde.bandwidth)
transformed = univariate_kde(element, bandwidth=bw)
Store.transfer_options(element, transformed, ['bw'])
return transformed


class bivariate_composite(Operation):

output_type = Polygons

def _process(self, element, key=None):
plot_opts = Store.lookup_options(Store.current_backend, element, 'plot').kwargs
bw = plot_opts.pop('bw', bivariate_kde.bandwidth)
filled = plot_opts.pop('filled', bivariate_kde.filled)
transformed = bivariate_kde(element, bandwidth=bw, filled=filled)
Store.transfer_options(element, transformed, ['bw', 'filled'])
return transformed

Compositor.register(Compositor("Distribution", univariate_composite, 'Area', 'data'))
Compositor.register(Compositor("Bivariate", bivariate_composite, 'Polygons', 'data'))
4 changes: 4 additions & 0 deletions holoviews/plotting/__init__.py
Expand Up @@ -9,6 +9,10 @@
from ..core.options import Cycle
from .plot import Plot
from .renderer import Renderer, HTML_TAGS # noqa (API import)
from .util import univariate_composite, bivariate_composite

Compositor.register(Compositor("Distribution", univariate_composite, 'Area', 'data'))
Compositor.register(Compositor("Bivariate", bivariate_composite, 'Polygons', 'data'))

def public(obj):
if not isinstance(obj, type): return False
Expand Down
27 changes: 27 additions & 0 deletions holoviews/plotting/util.py
Expand Up @@ -10,6 +10,8 @@
from ..core.spaces import get_nested_streams
from ..core.util import (match_spec, is_number, wrap_tuple, basestring,
get_overlay_spec, unique_iterator)
from ..element import Area, Polygons
from ..operation.stats import univariate_kde, bivariate_kde, Operation
from ..streams import LinkedStream

def displayable(obj):
Expand Down Expand Up @@ -451,6 +453,31 @@ def get_min_distance(element):
return 0


class univariate_composite(Operation):

output_type = Area

def _process(self, element, key=None):
plot_opts = Store.lookup_options(Store.current_backend, element, 'plot').kwargs
bw = plot_opts.pop('bw', univariate_kde.bandwidth)
transformed = univariate_kde(element, bandwidth=bw)
Store.transfer_options(element, transformed, ['bw'])
return transformed


class bivariate_composite(Operation):

output_type = Polygons

def _process(self, element, key=None):
plot_opts = Store.lookup_options(Store.current_backend, element, 'plot').kwargs
bw = plot_opts.pop('bw', bivariate_kde.bandwidth)
filled = plot_opts.pop('filled', bivariate_kde.filled)
transformed = bivariate_kde(element, bandwidth=bw, filled=filled)
Store.transfer_options(element, transformed, ['bw', 'filled'])
return transformed


def rgb2hex(rgb):
"""
Convert RGB(A) tuple to hex.
Expand Down

0 comments on commit 99114c0

Please sign in to comment.