Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _create_subplots(self, layout, axis, ranges, create_axes):
norm_opts = self._traverse_options(layout, 'norm', ['axiswise'], [Element])
axiswise = all(norm_opts['axiswise'])
if not ranges:
self.handles['fig'].set_size_inches(self.fig_inches)
subplots, subaxes = OrderedDict(), OrderedDict()
frame_ranges = self.compute_ranges(layout, None, ranges)
keys = self.keys[:1] if self.dynamic else self.keys
frame_ranges = OrderedDict([(key, self.compute_ranges(layout, key, frame_ranges))
for key in keys])
collapsed_layout = layout.clone(shared_data=False, id=layout.id)
r, c = (0, 0)
for coord in layout.keys(full_grid=True):
if not isinstance(coord, tuple): coord = (coord,)
view = layout.data.get(coord, None)
# Create subplot
if type(view) in (Layout, NdLayout):
raise SkipRendering("Cannot plot nested Layouts.")
if not displayable(view):
view = collate(view)
if view is not None:
vtype = view.type if isinstance(view, HoloMap) else view.__class__
show_legend = param.Boolean(default=True, doc="""
Whether to show legend for the plot.""")
xticks = param.Integer(0, precedence=-1)
style_opts = ['alpha', 'color', 'align', 'visible', 'edgecolor',
'log', 'facecolor', 'capsize', 'error_kw', 'hatch']
legend_specs = dict(LegendPlot.legend_specs, **{
'top': dict(bbox_to_anchor=(0., 1.02, 1., .102),
ncol=3, loc=3, mode="expand", borderaxespad=0.),
'bottom': dict(ncol=3, mode="expand", loc=2,
bbox_to_anchor=(0., -0.4, 1., .102),
borderaxespad=0.1)})
_dimensions = OrderedDict([('group', 0),
('category',1),
('stack',2)])
def __init__(self, element, **params):
super(BarPlot, self).__init__(element, **params)
self.values, self.bar_dimensions = self._get_values()
def _get_values(self):
"""
Get unique index value for each bar
"""
gi, ci, si =self.group_index, self.category_index, self.stack_index
ndims = self.hmap.last.ndims
dims = self.hmap.last.kdims
dimensions = []
def _create_subplot(self, key, obj, streams, ranges):
registry = Store.registry[self.renderer.backend]
ordering = util.layer_sort(self.hmap)
overlay_type = 1 if self.hmap.type == Overlay else 2
group_fn = lambda x: (x.type.__name__, x.last.group, x.last.label)
opts = {'overlaid': overlay_type}
if self.hmap.type == Overlay:
style_key = (obj.type.__name__,) + key
if self.overlay_dims:
opts['overlay_dims'] = self.overlay_dims
else:
if not isinstance(key, tuple): key = (key,)
style_key = group_fn(obj) + key
opts['overlay_dims'] = OrderedDict(zip(self.hmap.last.kdims, key))
if self.batched:
vtype = type(obj.last.last)
oidx = 0
else:
vtype = type(obj.last)
if style_key not in ordering:
ordering.append(style_key)
oidx = ordering.index(style_key)
plottype = registry.get(vtype, None)
if plottype is None:
self.param.warning(
"No plotting class for %s type and %s backend "
"found. " % (vtype.__name__, self.renderer.backend))
return None
def _create_subplots(self, layout, axis, ranges, create_axes):
norm_opts = self._traverse_options(layout, 'norm', ['axiswise'], [Element])
axiswise = all(norm_opts['axiswise'])
if not ranges:
self.handles['fig'].set_size_inches(self.fig_inches)
subplots, subaxes = OrderedDict(), OrderedDict()
frame_ranges = self.compute_ranges(layout, None, ranges)
keys = self.keys[:1] if self.dynamic else self.keys
frame_ranges = OrderedDict([(key, self.compute_ranges(layout, key, frame_ranges))
for key in keys])
collapsed_layout = layout.clone(shared_data=False, id=layout.id)
r, c = (0, 0)
for coord in layout.keys(full_grid=True):
if not isinstance(coord, tuple): coord = (coord,)
view = layout.data.get(coord, None)
# Create subplot
if type(view) in (Layout, NdLayout):
raise SkipRendering("Cannot plot nested Layouts.")
if not displayable(view):
view = collate(view)
if view is not None:
vtype = view.type if isinstance(view, HoloMap) else view.__class__
opts = self.lookup_options(view, 'plot').options
else:
vtype = None
elif (wsplits, hsplits) == (2,2):
layout_type = 'Triple'
# Get the AdjoinLayout at the specified coordinate
view = layouts[(r, c)]
positions = AdjointLayoutPlot.layout_dict[layout_type]
# Create temporary subplots to get projections types
# to create the correct subaxes for all plots in the layout
_, _, projs = self._create_subplots(layouts[(r, c)], positions,
None, frame_ranges, create=False)
gidx, gsinds = self.grid_situate(gidx, layout_type, cols)
layout_key, _ = layout_items.get((r, c), (None, None))
if isinstance(layout, NdLayout) and layout_key:
layout_dimensions = OrderedDict(zip(layout_dimensions, layout_key))
# Generate the axes and create the subplots with the appropriate
# axis objects, handling any Empty objects.
obj = layouts[(r, c)]
empty = isinstance(obj.main, Empty)
if view.main is None:
continue
elif empty:
obj = AdjointLayout([])
elif not view.traverse(lambda x: x, [Element]):
self.param.warning('%s is empty, skipping subplot.' % obj.main)
continue
elif self.transpose:
layout_count = (c*self.rows+(r+1))
else:
layout_count += 1
def _create_subplots(self, layout, ranges):
subplots = OrderedDict()
frame_ranges = self.compute_ranges(layout, None, ranges)
frame_ranges = OrderedDict([(key, self.compute_ranges(layout, key, frame_ranges))
for key in self.keys])
collapsed_layout = layout.clone(shared_data=False, id=layout.id)
for i, coord in enumerate(layout.keys(full_grid=True)):
if not isinstance(coord, tuple): coord = (coord,)
view = layout.data.get(coord, None)
# Create subplot
if view is not None:
vtype = view.type if isinstance(view, HoloMap) else view.__class__
opts = self.lookup_options(view, 'plot').options
else:
vtype = None
# Create axes
kwargs = {}
if isinstance(layout, GridMatrix):
if view.traverse(lambda x: x, [Histogram]):
def __init__(self, data, **params):
if type(data) == dict:
raise ValueError("ItemTable cannot accept a standard Python dictionary "
"as a well-defined item ordering is required.")
elif isinstance(data, dict): pass
elif isinstance(data, list):
data = OrderedDict(data)
else:
data = OrderedDict(list(data)) # Python 3
if not 'vdims' in params:
params['vdims'] = list(data.keys())
str_keys = OrderedDict((k.name if isinstance(k, Dimension)
else k ,v) for (k,v) in data.items())
super(ItemTable, self).__init__(str_keys, **params)
from collections import defaultdict
from ..core import OrderedDict
from ..core import Store
from ..core.util import basestring
class KeywordSettings(object):
"""
Base class for options settings used to specified collections of
keyword options.
"""
# Dictionary from keywords to allowed bounds/values
allowed = {}
defaults = OrderedDict([]) # Default keyword values.
options = OrderedDict(defaults.items()) # Current options
# Callables accepting (value, keyword, allowed) for custom exceptions
custom_exceptions = {}
# Hidden. Options that won't tab complete (for backward compatibility)
hidden = {}
@classmethod
def update_options(cls, options, items):
"""
Allows updating options depending on class attributes
and unvalidated options.
"""
pass
view = view if isinstance(view, AdjointLayout) else AdjointLayout([view])
layouts[(r, c)] = view
paths[r, c] = key
# Compute the layout type from shape
layout_lens = {1:'Single', 2:'Dual', 3: 'Triple'}
layout_type = layout_lens.get(len(view), 'Single')
# Get the AdjoinLayout at the specified coordinate
positions = AdjointLayoutPlot.layout_dict[layout_type]['positions']
# Create temporary subplots to get projections types
# to create the correct subaxes for all plots in the layout
layout_key, _ = layout_items.get((r, c), (None, None))
if isinstance(layout, NdLayout) and layout_key:
layout_dimensions = OrderedDict(zip(layout_dimensions, layout_key))
# Generate the axes and create the subplots with the appropriate
# axis objects, handling any Empty objects.
empty = isinstance(view.main, Empty)
if empty or view.main is None:
continue
elif not view.traverse(lambda x: x, [Element]):
self.param.warning('%s is empty, skipping subplot.' % view.main)
continue
else:
layout_count += 1
num = 0 if empty else layout_count
subplots, adjoint_layout = self._create_subplots(
view, positions, layout_dimensions, frame_ranges, num=num
)