How to use the altair.vegalite.v4.schema.core function in altair

To help you get started, we’ve selected a few altair examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github altair-viz / altair / altair / vegalite / v4 / api.py View on Github external
def _check_if_valid_subspec(spec, classname):
    """Check if the spec is a valid sub-spec.

    If it is not, then raise a ValueError
    """
    err = ('Objects with "{0}" attribute cannot be used within {1}. '
           'Consider defining the {0} attribute in the {1} object instead.')

    if not isinstance(spec, (core.SchemaBase, dict)):
        raise ValueError("Only chart objects can be used in {0}.".format(classname))
    for attr in TOPLEVEL_ONLY_KEYS:
        if isinstance(spec, core.SchemaBase):
            val = getattr(spec, attr, Undefined)
        else:
            val = spec.get(attr, Undefined)
        if val is not Undefined:
            raise ValueError(err.format(attr, classname))
github altair-viz / altair / altair / vegalite / v4 / api.py View on Github external
True

        See Also
        --------
        alt.AggregateTransform : underlying transform object

        """
        if aggregate is Undefined:
            aggregate = []
        for key, val in kwds.items():
            parsed = utils.parse_shorthand(val)
            dct = {'as': key,
                   'field': parsed.get('field', Undefined),
                   'op': parsed.get('aggregate', Undefined)}
            aggregate.append(core.AggregatedFieldDef(**dct))
        return self._add_transform(core.AggregateTransform(aggregate=aggregate,
                                                           groupby=groupby))
github altair-viz / altair / altair / vegalite / v4 / schema / mixins.py View on Github external
    @use_signature(core.BoxPlotConfig)
    def configure_boxplot(self, *args, **kwargs):
        copy = self.copy(deep=['config'])
        if copy.config is Undefined:
            copy.config = core.Config()
        copy.config["boxplot"] = core.BoxPlotConfig(*args, **kwargs)
        return copy
github altair-viz / altair / altair / vegalite / v4 / api.py View on Github external
Parameters
        ----------
        sample : float
            The maximum number of data objects to include in the sample. Default: 1000.

        Returns
        -------
        self : Chart object
            returns chart to allow for chaining

        See Also
        --------
        alt.SampleTransform : underlying transform object
        """
        return self._add_transform(core.SampleTransform(sample))
github altair-viz / altair / altair / vegalite / v4 / api.py View on Github external
If the lengths of parallel arrays do not match,
            the longest array will be used with ``null`` values added for missing entries.
        as : List(string)
            The output field names for extracted array values.
            **Default value:** The field name of the corresponding array field

        Returns
        -------
        self : Chart object
            returns chart to allow for chaining

        See Also
        --------
        alt.FlattenTransform : underlying transform object
        """
        return self._add_transform(core.FlattenTransform(flatten=flatten, **{'as': as_}))
github altair-viz / altair / altair / vegalite / v4 / api.py View on Github external
_class_is_valid_at_instantiation = False

    def to_dict(self, *args, **kwargs):
        copy = self.copy(deep=False)
        context = kwargs.get('context', {})
        data = context.get('data', None)
        if isinstance(self.row, str):
            copy.row = core.FacetFieldDef(**utils.parse_shorthand(self.row, data))
        if isinstance(self.column, str):
            copy.column = core.FacetFieldDef(**utils.parse_shorthand(self.column, data))
        return super(FacetMapping, copy).to_dict(*args, **kwargs)


# ------------------------------------------------------------------------
# Encoding will contain channel objects that aren't valid at instantiation
core.FacetedEncoding._class_is_valid_at_instantiation = False

# ------------------------------------------------------------------------
# These are parameters that are valid at the top level, but are not valid
# for specs that are within a composite chart
# (layer, hconcat, vconcat, facet, repeat)
TOPLEVEL_ONLY_KEYS = {'background', 'config', 'autosize', 'padding', '$schema'}


def _get_channels_mapping():
    mapping = {}
    for attr in dir(channels):
        cls = getattr(channels, attr)
        if isinstance(cls, type) and issubclass(cls, core.SchemaBase):
            mapping[cls] = attr.replace('Value', '').lower()
    return mapping
github altair-viz / altair / altair / vegalite / v4 / api.py View on Github external
@utils.use_signature(core.MultiSelection)
def selection_multi(**kwargs):
    """Create a selection with type='multi'"""
    return selection(type='multi', **kwargs)
github altair-viz / altair / altair / vegalite / v4 / api.py View on Github external
----------
    name : string (optional)
        The name of the selection. If not specified, a unique name will be
        created.
    type : string
        The type of the selection: one of ["interval", "single", or "multi"]
    **kwds :
        additional keywords will be used to construct a SelectionDef instance
        that controls the selection.

    Returns
    -------
    selection: Selection
        The selection object that can be used in chart creation.
    """
    return Selection(name, core.SelectionDef(type=type, **kwds))
github altair-viz / altair / altair / vegalite / v4 / api.py View on Github external
@utils.use_signature(core.BindRadioSelect)
def binding_select(**kwargs):
    """A select binding"""
    return core.BindRadioSelect(input='select', **kwargs)
github altair-viz / altair / altair / vegalite / v4 / schema / mixins.py View on Github external
    @use_signature(core.TitleConfig)
    def configure_title(self, *args, **kwargs):
        copy = self.copy(deep=['config'])
        if copy.config is Undefined:
            copy.config = core.Config()
        copy.config["title"] = core.TitleConfig(*args, **kwargs)
        return copy