Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
threshold=self.p.threshold,
how=self.p.how, shape=self.p.shape).data
def split_dataframe(path_df):
"""
Splits a dataframe of paths separated by NaNs into individual
dataframes.
"""
splits = np.where(path_df.iloc[:, 0].isnull())[0]+1
return [df for df in np.split(path_df, splits) if len(df) > 1]
class _connect_edges(Operation):
split = param.Boolean(default=False, doc="""
Determines whether bundled edges will be split into individual edges
or concatenated with NaN separators.""")
def _bundle(self, position_df, edges_df):
raise NotImplementedError('_connect_edges is an abstract baseclass '
'and does not implement any actual bundling.')
def _process(self, element, key=None):
index = element.nodes.kdims[2].name
rename_edges = {d.name: v for d, v in zip(element.kdims[:2], ['source', 'target'])}
rename_nodes = {d.name: v for d, v in zip(element.nodes.kdims[:2], ['x', 'y'])}
position_df = element.nodes.redim(**rename_nodes).dframe([0, 1, 2]).set_index(index)
edges_df = element.redim(**rename_edges).dframe([0, 1])
paths = self._bundle(position_df, edges_df)
paths = paths.rename(columns={v: k for k, v in rename_nodes.items()})
paths = split_dataframe(paths) if self.p.split else [paths]
def __init__(self, *objects, **params):
super(WidgetBox, self).__init__(*objects, **params)
if self.disabled:
self._disable_widgets()
class Tabs(ListPanel):
"""
Panel of Viewables to be displayed in separate tabs.
"""
active = param.Integer(default=0, bounds=(0, None), doc="""
Number of the currently active tab.""")
closable = param.Boolean(default=False, doc="""
Whether it should be possible to close tabs.""")
dynamic = param.Boolean(default=False, doc="""
Dynamically populate only the active tab.""")
objects = param.List(default=[], doc="""
The list of child objects that make up the tabs.""")
tabs_location = param.ObjectSelector(
default='above', objects=['above', 'below', 'left', 'right'], doc="""
The location of the tabs relative to the tab contents.""")
height = param.Integer(default=None, bounds=(0, None))
width = param.Integer(default=None, bounds=(0, None))
from ...core import util
from ...core import (OrderedDict, NdOverlay, DynamicMap, Dataset,
CompositeOverlay, Element3D, Element)
from ...core.options import abbreviated_exception
from ...element import Graph, Path
from ...streams import Stream
from ...util.transform import dim
from ..plot import GenericElementPlot, GenericOverlayPlot
from ..util import dynamic_update, process_cmap, color_intervals, dim_range_key
from .plot import MPLPlot, mpl_rc_context
from .util import mpl_version, validate, wrap_formatter
class ElementPlot(GenericElementPlot, MPLPlot):
apply_ticks = param.Boolean(default=True, doc="""
Whether to apply custom ticks.""")
aspect = param.Parameter(default='square', doc="""
The aspect ratio mode of the plot. By default, a plot may
select its own appropriate aspect ratio but sometimes it may
be necessary to force a square aspect ratio (e.g. to display
the plot as an element of a grid). The modes 'auto' and
'equal' correspond to the axis modes of the same name in
matplotlib, a numeric value specifying the ratio between plot
width and height may also be passed. To control the aspect
ratio between the axis scales use the data_aspect option
instead.""")
data_aspect = param.Number(default=None, doc="""
Defines the aspect of the axis scaling, i.e. the ratio of
y-unit to x-unit.""")
expand = param.Boolean(default=False, doc="""
Whether the x_range and y_range should be allowed to expand
beyond the extent of the data. Setting this value to True is
useful for the case where you want to ensure a certain size of
output grid, e.g. if you are doing masking or other arithmetic
on the grids. A value of False ensures that the grid is only
just as large as it needs to be to contain the data, which will
be faster and use less memory if the resulting aggregate is
being overlaid on a much larger background.""")
interpolation = param.ObjectSelector(default='nearest',
objects=['linear', 'nearest', 'bilinear', None, False], doc="""
Interpolation method""")
upsample = param.Boolean(default=False, doc="""
Whether to allow upsampling if the source array is smaller
than the requested array. Setting this value to True will
enable upsampling using the interpolation method, when the
requested width and height are larger than what is available
on the source grid. If upsampling is disabled (the default)
the width and height are clipped to what is available on the
source array.""")
def _get_xarrays(self, element, coords, xtype, ytype):
x, y = element.kdims
dims = [y.name, x.name]
irregular = any(element.interface.irregular(element, d)
for d in dims)
if irregular:
coord_dict = {x.name: (('y', 'x'), coords[0]),
y.name: (('y', 'x'), coords[1])}
_comms = param.ObjectSelector(
default='default', objects=['default', 'ipywidgets'], doc="""
Whether to render output in Jupyter with the default Jupyter
extension or use the jupyter_bokeh ipywidget model.""")
_console_output = param.ObjectSelector(default='accumulate', allow_None=True,
objects=['accumulate', 'replace', 'disable',
False], doc="""
How to log errors and stdout output triggered by callbacks
from Javascript in the notebook.""")
_cookie_secret = param.String(default=None, doc="""
Configure to enable getting/setting secure cookies.""")
_embed = param.Boolean(default=False, allow_None=True, doc="""
Whether plot data will be embedded.""")
_embed_json = param.Boolean(default=False, doc="""
Whether to save embedded state to json files.""")
_embed_json_prefix = param.String(default='', doc="""
Prefix for randomly generated json directories.""")
_embed_load_path = param.String(default=None, doc="""
Where to load json files for embedded state.""")
_embed_save_path = param.String(default='./', doc="""
Where to save json files for embedded state.""")
_log_level = param.Selector(
default=None, objects=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
context,
)
if model is not None:
model.update(rebuild=True)
model.update(arrays=self._arrays)
model.update(scene=self._scene)
class VTKRenderWindowSynchronized(BaseVTKRenderWindow, SyncHelpers):
"""
VTK panes allow rendering VTK objects.
Synchronize a vtkRenderWindow constructs on python side
with a custom bokeh model on javascript side
"""
_one_time_reset = param.Boolean(default=False)
_rename = dict(_one_time_reset='one_time_reset',
**BaseVTKRenderWindow._rename)
_updates = True
@classmethod
def applies(cls, obj, **kwargs):
serialize_on_instantiation = kwargs.get('serialize_on_instantiation', False)
return (super(VTKRenderWindowSynchronized, cls).applies(obj, **kwargs) and
not serialize_on_instantiation)
def __init__(self, object=None, **params):
if object is None:
object = self.make_ren_win()
super(VTKRenderWindowSynchronized, self).__init__(object, **params)
sources = [o for i, inputs in self.stream_sources.items()
for o in inputs if i in zorders]
else:
sources = [self.hmap.last]
return sources
class GenericElementPlot(DimensionedPlot):
"""
Plotting baseclass to render contents of an Element. Implements
methods to get the correct frame given a HoloMap, axis labels and
extents and titles.
"""
apply_ranges = param.Boolean(default=True, doc="""
Whether to compute the plot bounds from the data itself.""")
apply_extents = param.Boolean(default=True, doc="""
Whether to apply extent overrides on the Elements""")
bgcolor = param.ClassSelector(class_=(str, tuple), default=None, doc="""
If set bgcolor overrides the background color of the axis.""")
default_span = param.ClassSelector(default=2.0, class_=(int, float, tuple), doc="""
Defines the span of an axis if the axis range is zero, i.e. if
the lower and upper end of an axis are equal or no range is
defined at all. For example if there is a single datapoint at
0 a default_span of 2.0 will result in axis ranges spanning
from -1 to 1.""")
invert_axes = param.Boolean(default=False, doc="""
HistogramPlot can plot DataHistograms and DataStacks of
DataHistograms, which can be displayed as a single frame or
animation.
"""
style_opts = param.List(default=['alpha', 'color', 'align',
'visible', 'edgecolor', 'log',
'ecolor', 'capsize', 'error_kw',
'hatch'], constant=True, doc="""
The style options for HistogramPlot match those of
matplotlib's bar command.""")
num_ticks = param.Integer(default=5, doc="""
If colorbar is enabled the number of labels will be overwritten.""")
rescale_individually = param.Boolean(default=True, doc="""
Whether to use redraw the axes per stack or per view.""")
show_frame = param.Boolean(default=False, doc="""
Disabled by default for clarity.""")
_stack_type = DataStack
def __init__(self, curves, zorder=0, **kwargs):
self.center = False
self.cyclic = False
self.cyclic_index = 0
self.ax = None
self._stack = self._check_stack(curves, Histogram)
super(HistogramPlot, self).__init__(zorder, **kwargs)
User-specified colorbar axis range limits for the plot, as a tuple (low,high).
If specified, takes precedence over data and dimension ranges.""")
colorbar = param.Boolean(default=False, doc="""
Whether to display a colorbar.""")
color_levels = param.ClassSelector(default=None, class_=(int, list), doc="""
Number of discrete colors to use when colormapping or a set of color
intervals defining the range of values to map each color to.""")
colorbar_opts = param.Dict(default={}, doc="""
Allows setting including borderwidth, showexponent, nticks,
outlinecolor, thickness, bgcolor, outlinewidth, bordercolor,
ticklen, xpad, ypad, tickangle...""")
symmetric = param.Boolean(default=False, doc="""
Whether to make the colormap symmetric around zero.""")
def get_color_opts(self, eldim, element, ranges, style):
opts = {}
dim_name = dim_range_key(eldim)
if self.colorbar:
if isinstance(eldim, dim):
title = str(eldim) if eldim.ops else str(eldim)[1:-1]
else:
title = eldim.pprint_label
opts['colorbar'] = dict(title=title, **self.colorbar_opts)
opts['showscale'] = True
else:
opts['showscale'] = False
if eldim:
Whether to apply extent overrides on the Elements""")
bgcolor = param.ClassSelector(class_=(str, tuple), default=None, doc="""
If set bgcolor overrides the background color of the axis.""")
default_span = param.ClassSelector(default=2.0, class_=(int, float, tuple), doc="""
Defines the span of an axis if the axis range is zero, i.e. if
the lower and upper end of an axis are equal or no range is
defined at all. For example if there is a single datapoint at
0 a default_span of 2.0 will result in axis ranges spanning
from -1 to 1.""")
invert_axes = param.Boolean(default=False, doc="""
Whether to invert the x- and y-axis""")
invert_xaxis = param.Boolean(default=False, doc="""
Whether to invert the plot x-axis.""")
invert_yaxis = param.Boolean(default=False, doc="""
Whether to invert the plot y-axis.""")
logx = param.Boolean(default=False, doc="""
Whether the x-axis of the plot will be a log axis.""")
logy = param.Boolean(default=False, doc="""
Whether the y-axis of the plot will be a log axis.""")
padding = param.ClassSelector(default=0, class_=(int, float, tuple), doc="""
Fraction by which to increase auto-ranged extents to make
datapoints more visible around borders.
To compute padding, the axis whose screen size is largest is