MCPcopy Create free account
hub / github.com/holoviz/hvplot / hvPlotBase

Class hvPlotBase

hvplot/plotting/core.py:26–151  ·  view source on GitHub ↗

Internal base class. Concrete subclasses must implement plotting methods (e.g. `line`, `scatter`, `image`). A plotting method must call `self` which will effectively create a HoloViewsConverter and call it to return a HoloViews object. Concrete subclasses are meant to be mount

Source from the content-addressed store, hash-verified

24
25
26class hvPlotBase:
27 """
28 Internal base class.
29
30 Concrete subclasses must implement plotting methods (e.g. `line`, `scatter`, `image`).
31 A plotting method must call `self` which will effectively create a HoloViewsConverter
32 and call it to return a HoloViews object.
33
34 Concrete subclasses are meant to be mounted onto a datastructure property, e.g.:
35
36 ```
37 _patch_plot = lambda self: hvPlotTabular(self)
38 _patch_plot.__doc__ = hvPlotTabular.__call__.__doc__
39 plot_prop = property(_patch_plot)
40 setattr(pd.DataFrame, 'hvplot', plot_prop)
41 ```
42 """
43
44 __all__ = []
45
46 def __init__(self, data, custom_plots={}, **metadata):
47 if 'query' in metadata:
48 data = data.query(metadata.pop('query'))
49 if 'sel' in metadata:
50 data = data.sel(**metadata.pop('sel'))
51 if 'isel' in metadata:
52 data = data.isel(**metadata.pop('isel'))
53 self._data = data
54 self._plots = custom_plots
55 self._metadata = metadata
56
57 def __call__(self, x=None, y=None, kind=None, **kwds):
58 # Convert an array-like to a list
59 x = list(x) if is_list_like(x) else x
60 y = list(y) if is_list_like(y) else y
61
62 if isinstance(kind, str) and kind not in self.__all__:
63 raise NotImplementedError(f"kind='{kind}' for data of type {type(self._data)}")
64
65 if isinstance(kind, str) and kind == 'explorer':
66 return self.explorer(x=x, y=y, **kwds)
67
68 if panel_available:
69 panel_args = ['widgets', 'widget_location', 'widget_layout', 'widget_type']
70 panel_dict = {}
71 for k in panel_args:
72 if k in kwds:
73 panel_dict[k] = kwds.pop(k)
74 dynamic, arg_deps, arg_names = process_dynamic_args(x, y, kind, **kwds)
75 if dynamic or arg_deps:
76
77 @pn.depends(*arg_deps, **dynamic)
78 def callback(*args, **dyn_kwds):
79 xd = dyn_kwds.pop('x', x)
80 yd = dyn_kwds.pop('y', y)
81 kindd = dyn_kwds.pop('kind', kind)
82
83 combined_kwds = dict(kwds, **dyn_kwds)

Callers 1

__getattribute__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…