panel.pane.vega module#
- class panel.pane.vega.Vega(object=None, **params)[source]#
Bases:
ModelPaneThe Vega pane renders Vega-lite based plots (including those from Altair) inside a panel.
Note
to use the Vega pane, the Panel extension has to be
loaded with ‘vega’ as an argument to ensure that vega.js is initialized. - it supports selection events - it optimizes the plot rendering by using binary serialization for any array data found on the Vega/Altair object, providing huge speedups over the standard JSON serialization employed by Vega natively.
Reference: https://panel.holoviz.org/reference/panes/Vega.html
- Example:
>>> pn.extension('vega') >>> Vega(some_vegalite_dict_or_altair_object, height=240)
Methods
applies(obj)Returns boolean or float indicating whether the Pane can render the object.
export(fmt[, as_pane])Exports the Vega spec to various formats.
is_altair
Parameter Definitions
Parameters inherited from:
panel.viewable.Layoutable: align, aspect_ratio, css_classes, design, height, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visiblepanel.viewable.Viewable: loadingpanel.pane.base.PaneBase: margin, default_layout, objectdebounce = ClassSelector(class_=(<class 'int'>, <class 'dict'>), default=20, label='Debounce')Declares the debounce time in milliseconds either for all events or if a dictionary is provided for individual events.
selection = ClassSelector(allow_None=True, class_=<class 'param.parameterized.Parameterized'>, label='Selection')The Selection object reflects any selections available on the supplied vega plot into Python.
show_actions = Boolean(default=False, label='Show actions')Whether to show Vega actions.
theme = Selector(allow_None=True, label='Theme', names={}, objects=['excel', 'ggplot2', 'quartz', 'vox', 'fivethirtyeight', 'dark', 'latimes', 'urbaninstitute', 'googlecharts'])A theme to apply to the plot. Must be one of ‘excel’, ‘ggplot2’, ‘quartz’, ‘vox’, ‘fivethirtyeight’, ‘dark’, ‘latimes’, ‘urbaninstitute’, or ‘googlecharts’.
- classmethod applies(obj: Any) float | bool | None[source]#
Returns boolean or float indicating whether the Pane can render the object.
If the priority of the pane is set to None, this method may also be used to define a float priority depending on the object being rendered.
- export(fmt: VEGA_EXPORT_FORMATS, as_pane: bool = False, **kwargs: dict) bytes | str | dict | ModelPane[source]#
Exports the Vega spec to various formats.
The export method converts the Vega/Altair specification to different output formats. It requires vl-convert-python to be installed.
- Parameters:
- fmtstr
The format to export to. Must be one of ‘png’, ‘jpeg’, ‘svg’, ‘pdf’, ‘html’, ‘url’, ‘scenegraph’.
- as_panebool, default False
If True, wraps the exported data in the appropriate Panel pane.
- **kwargsdict
Additional keyword arguments passed to the vl-convert functions.
- Returns:
- bytes | str | ModelPane
The exported data in the requested format, or a Panel pane if as_pane=True.
- Raises:
- ImportError
If vl-convert-python is not installed.
- ValueError
If an unsupported format is specified.
Examples
>>> vega_pane = Vega(spec_dict) >>> png_bytes = vega_pane.export('png') >>> image_pane = vega_pane.export('png', as_pane=True)