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

Cleaned up CompositePlot instantiation #840

Merged
merged 6 commits into from
Aug 31, 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
24 changes: 4 additions & 20 deletions holoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,11 @@ class GridPlot(BokehPlot, GenericCompositePlot):
object.
"""

def __init__(self, layout, ranges=None, keys=None, dimensions=None,
layout_num=1, **params):
def __init__(self, layout, ranges=None, layout_num=1, **params):
if not isinstance(layout, GridSpace):
raise Exception("GridPlot only accepts GridSpace.")

self.layout = layout
self.rows, self.cols = layout.shape
self.layout_num = layout_num
extra_opts = self.lookup_options(layout, 'plot').options
if not keys or not dimensions:
dimensions, keys = traversal.unique_dimkeys(layout)
if 'uniform' not in params:
params['uniform'] = traversal.uniform(layout)

dynamic, sampled = get_dynamic_mode(layout)
if sampled:
initialize_sampled(layout, dimensions, keys[0])

super(GridPlot, self).__init__(keys=keys, dimensions=dimensions,
dynamic=dynamic,
**dict(extra_opts, **params))
super(GridPlot, self).__init__(layout=layout, layout_num=layout_num,
ranges=ranges, **params)
self.subplots, self.layout = self._create_subplots(layout, ranges)


Expand Down Expand Up @@ -548,7 +532,7 @@ def update_frame(self, key, ranges=None):
subplot.update_frame(key, ranges)


class AdjointLayoutPlot(BokehPlot, GenericCompositePlot):
class AdjointLayoutPlot(BokehPlot):

layout_dict = {'Single': {'positions': ['main']},
'Dual': {'positions': ['main', 'right']},
Expand Down
20 changes: 4 additions & 16 deletions holoviews/plotting/mpl/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,11 @@ class GridPlot(CompositePlot):
Rotation angle of the yticks.""")

def __init__(self, layout, axis=None, create_axes=True, ranges=None,
keys=None, dimensions=None, layout_num=1, **params):
layout_num=1, **params):
if not isinstance(layout, GridSpace):
raise Exception("GridPlot only accepts GridSpace.")
self.layout = layout
self.cols, self.rows = layout.shape
self.layout_num = layout_num
extra_opts = self.lookup_options(layout, 'plot').options
if not keys or not dimensions:
dimensions, keys = traversal.unique_dimkeys(layout)
if 'uniform' not in params:
params['uniform'] = traversal.uniform(layout)
dynamic, sampled = get_dynamic_mode(layout)
if sampled:
initialize_sampled(layout, dimensions, keys[0])
super(GridPlot, self).__init__(keys=keys, dimensions=dimensions,
dynamic=dynamic,
**dict(extra_opts, **params))
super(GridPlot, self).__init__(layout, layout_num=layout_num,
ranges=ranges, **params)
# Compute ranges layoutwise
grid_kwargs = {}
if axis is not None:
Expand Down Expand Up @@ -566,7 +554,7 @@ def _adjust_subplots(self, axis, subaxes):



class AdjointLayoutPlot(CompositePlot):
class AdjointLayoutPlot(MPLPlot):
"""
LayoutPlot allows placing up to three Views in a number of
predefined and fixed layouts, which are defined by the layout_dict
Expand Down
40 changes: 26 additions & 14 deletions holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,12 @@ def __init__(self, element, keys=None, ranges=None, dimensions=None,
if self.batched:
plot_element = plot_element.last

subplot = not keys
if subplot:
dimensions = self.hmap.kdims
keys = list(self.hmap.data.keys())

self.style = self.lookup_options(plot_element, 'style') if style is None else style
dimensions = self.hmap.kdims if dimensions is None else dimensions
keys = keys if keys else list(self.hmap.data.keys())
plot_opts = self.lookup_options(plot_element, 'plot').options

dynamic = False if not isinstance(element, DynamicMap) or element.sampled else element.mode
Expand Down Expand Up @@ -883,6 +886,26 @@ def get_extents(self, overlay, ranges):

class GenericCompositePlot(DimensionedPlot):

def __init__(self, layout, keys=None, dimensions=None, **params):
dynamic, sampled = get_dynamic_mode(layout)
if sampled:
initialize_sampled(layout, dimensions, keys[0])

if 'uniform' not in params:
params['uniform'] = traversal.uniform(layout)

subplot = not keys
if subplot:
dimensions, keys = traversal.unique_dimkeys(layout)

self.layout = layout
self.rows, self.cols = layout.shape
super(GenericCompositePlot, self).__init__(keys=keys,
dynamic=dynamic,
dimensions=dimensions,
**params)


def _get_frame(self, key):
"""
Creates a clone of the Layout with the nth-frame for each
Expand Down Expand Up @@ -956,18 +979,7 @@ def __init__(self, layout, **params):
if len(layout.values()) == 0:
raise ValueError("Cannot display empty layout")

self.layout = layout
super(GenericLayoutPlot, self).__init__(layout, **params)
self.subplots = {}
self.rows, self.cols = layout.shape
self.coords = list(product(range(self.rows),
range(self.cols)))
dynamic, sampled = get_dynamic_mode(layout)
dimensions, keys = traversal.unique_dimkeys(layout)
if sampled:
initialize_sampled(layout, dimensions, keys[0])

uniform = traversal.uniform(layout)
plotopts = self.lookup_options(layout, 'plot').options
super(GenericLayoutPlot, self).__init__(keys=keys, dimensions=dimensions,
uniform=uniform, dynamic=dynamic,
**dict(plotopts, **params))