altair.Scale

class altair.Scale(align=Undefined, base=Undefined, bins=Undefined, clamp=Undefined, constant=Undefined, domain=Undefined, exponent=Undefined, interpolate=Undefined, nice=Undefined, padding=Undefined, paddingInner=Undefined, paddingOuter=Undefined, range=Undefined, round=Undefined, scheme=Undefined, type=Undefined, zero=Undefined, **kwds)

Scale schema wrapper

Mapping(required=[])

Attributes:
align : float

The alignment of the steps within the scale range.

This value must lie in the range [0,1]. A value of 0.5 indicates that the steps should be centered within the range. A value of 0 or 1 may be used to shift the bands to one side, say to position them adjacent to an axis.

Default value: 0.5

base : float

The logarithm base of the log scale (default 10 ).

bins : List(float)

An array of bin boundaries over the scale domain. If provided, axes and legends will use the bin boundaries to inform the choice of tick marks and text labels.

clamp : boolean

If true, values that exceed the data domain are clamped to either the minimum or maximum range value

Default value: derived from the scale config ‘s clamp ( true by default).

constant : float

A constant determining the slope of the symlog function around zero. Only used for symlog scales.

Default value: 1

domain : anyOf(List(float), List(string), List(boolean), List(DateTime),
enum(‘unaggregated’), :class:`SelectionExtent`)

Customized domain values.

For quantitative fields, domain can take the form of a two-element array with minimum and maximum values. Piecewise scales can be created by providing a domain with more than two entries. If the input field is aggregated, domain can also be a string value "unaggregated", indicating that the domain should include the raw data values prior to the aggregation.

For temporal fields, domain can be a two-element array minimum and maximum values, in the form of either timestamps or the DateTime definition objects.

For ordinal and nominal fields, domain can be an array that lists valid input values.

The selection property can be used to interactively determine the scale domain.

exponent : float

The exponent of the pow scale.

interpolate : anyOf(ScaleInterpolate, ScaleInterpolateParams)

The interpolation method for range values. By default, a general interpolator for numbers, dates, strings and colors (in HCL space) is used. For color ranges, this property allows interpolation in alternative color spaces. Legal values include rgb, hsl, hsl-long, lab, hcl, hcl-long, cubehelix and cubehelix-long (‘-long’ variants use longer paths in polar coordinate spaces). If object-valued, this property accepts an object with a string-valued type property and an optional numeric gamma property applicable to rgb and cubehelix interpolators. For more, see the d3-interpolate documentation.

  • Default value: hcl
nice : anyOf(boolean, float, NiceTime, Mapping(required=[interval, step]))

Extending the domain so that it starts and ends on nice round values. This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value. Nicing is useful if the domain is computed from data and may be irregular. For example, for a domain of [0.201479…, 0.996679…], a nice domain might be [0.2, 1.0].

For quantitative scales such as linear, nice can be either a boolean flag or a number. If nice is a number, it will represent a desired tick count. This allows greater control over the step size used to extend the bounds, guaranteeing that the returned ticks will exactly cover the domain.

For temporal fields with time and utc scales, the nice value can be a string indicating the desired time interval. Legal values are "millisecond", "second", "minute", "hour", "day", "week", "month", and "year". Alternatively, time and utc scales can accept an object-valued interval specifier of the form {"interval": "month", "step": 3}, which includes a desired number of interval steps. Here, the domain would snap to quarter (Jan, Apr, Jul, Oct) boundaries.

Default value: true for unbinned quantitative fields; false otherwise.

padding : float

For * continuous * scales, expands the scale domain to accommodate the specified number of pixels on each of the scale range. The scale range must represent pixels for this parameter to function as intended. Padding adjustment is performed prior to all other adjustments, including the effects of the  zeronicedomainMin, and domainMax  properties.

For * band * scales, shortcut for setting paddingInner and paddingOuter to the same value.

For * point * scales, alias for paddingOuter.

Default value: For continuous scales, derived from the scale config ‘s continuousPadding. For band and point scales, see paddingInner and paddingOuter. By default, Vega-Lite sets padding such that width/height = number of unique values * step.

paddingInner : float

The inner padding (spacing) within each band step of band scales, as a fraction of the step size. This value must lie in the range [0,1].

For point scale, this property is invalid as point scales do not have internal band widths (only step sizes between bands).

Default value: derived from the scale config ‘s bandPaddingInner.

paddingOuter : float

The outer padding (spacing) at the ends of the range of band and point scales, as a fraction of the step size. This value must lie in the range [0,1].

Default value: derived from the scale config ‘s bandPaddingOuter for band scales and pointPadding for point scales. By default, Vega-Lite sets outer padding such that width/height = number of unique values * step.

range : anyOf(List(float), List(string), RangeEnum)

The range of the scale. One of:

A string indicating a pre-defined named scale range (e.g., example, "symbol", or "diverging" ).

For continuous scales, two-element array indicating minimum and maximum values, or an array with more than two entries for specifying a piecewise scale.

For discrete and discretizing scales, an array of desired output values.

Notes:

1) For color scales you can also specify a color scheme instead of range.

2) Any directly specified range for x and y channels will be ignored. Range can be customized via the view’s corresponding size ( width and height ).

round : boolean

If true, rounds numeric output values to integers. This can be helpful for snapping to the pixel grid.

Default value: false.

scheme : anyOf(string, SchemeParams)

A string indicating a color scheme name (e.g., "category10" or "blues" ) or a scheme parameter object.

Discrete color schemes may be used with discrete or discretizing scales. Continuous color schemes are intended for use with color scales.

For the full list of supported schemes, please refer to the Vega Scheme reference.

type : ScaleType

The type of scale. Vega-Lite supports the following categories of scale types:

1) Continuous Scales – mapping continuous domains to continuous output ranges ( “linear”, “pow”, “sqrt”, “symlog”, “log”, “time”, “utc”.

2) Discrete Scales – mapping discrete domains to discrete ( “ordinal” ) or continuous ( “band” and “point” ) output ranges.

3) Discretizing Scales – mapping continuous domains to discrete output ranges “bin-ordinal”, “quantile”, “quantize” and “threshold”.

Default value: please see the scale type table.

zero : boolean

If true, ensures that a zero baseline value is included in the scale domain.

Default value: true for x and y channels if the quantitative field is not binned and no custom domain is provided; false otherwise.

Note: Log, time, and utc scales do not support zero.

__init__(align=Undefined, base=Undefined, bins=Undefined, clamp=Undefined, constant=Undefined, domain=Undefined, exponent=Undefined, interpolate=Undefined, nice=Undefined, padding=Undefined, paddingInner=Undefined, paddingOuter=Undefined, range=Undefined, round=Undefined, scheme=Undefined, type=Undefined, zero=Undefined, **kwds)

Methods

__init__([align, base, bins, clamp, …])
copy([deep, ignore]) Return a copy of the object
from_dict(dct[, validate, _wrapper_classes]) Construct class from a dictionary representation
from_json(json_string[, validate]) Instantiate the object from a valid JSON string
resolve_references([schema]) Resolve references in the context of this object’s schema or root schema.
to_dict([validate, ignore, context]) Return a dictionary representation of the object
to_json([validate, ignore, context, indent, …]) Emit the JSON representation for this object as a string.
validate(instance[, schema]) Validate the instance against the class schema in the context of the rootschema.
validate_property(name, value[, schema]) Validate a property against property schema in the context of the
copy(deep=True, ignore=())

Return a copy of the object

Parameters:
deep : boolean or list, optional

If True (default) then return a deep copy of all dict, list, and SchemaBase objects within the object structure. If False, then only copy the top object. If a list or iterable, then only copy the listed attributes.

ignore : list, optional

A list of keys for which the contents should not be copied, but only stored by reference.

from_dict(dct, validate=True, _wrapper_classes=None)

Construct class from a dictionary representation

Parameters:
dct : dictionary

The dict from which to construct the class

validate : boolean

If True (default), then validate the input against the schema.

_wrapper_classes : list (optional)

The set of SchemaBase classes to use when constructing wrappers of the dict inputs. If not specified, the result of cls._default_wrapper_classes will be used.

Returns:
obj : Schema object

The wrapped schema

Raises:
jsonschema.ValidationError :

if validate=True and dct does not conform to the schema

from_json(json_string, validate=True, **kwargs)

Instantiate the object from a valid JSON string

Parameters:
json_string : string

The string containing a valid JSON chart specification.

validate : boolean

If True (default), then validate the input against the schema.

**kwargs :

Additional keyword arguments are passed to json.loads

Returns:
chart : Chart object

The altair Chart object built from the specification.

resolve_references(schema=None)

Resolve references in the context of this object’s schema or root schema.

to_dict(validate=True, ignore=None, context=None)

Return a dictionary representation of the object

Parameters:
validate : boolean or string

If True (default), then validate the output dictionary against the schema. If “deep” then recursively validate all objects in the spec. This takes much more time, but it results in friendlier tracebacks for large objects.

ignore : list

A list of keys to ignore. This will not passed to child to_dict function calls.

context : dict (optional)

A context dictionary that will be passed to all child to_dict function calls

Returns:
dct : dictionary

The dictionary representation of this object

Raises:
jsonschema.ValidationError :

if validate=True and the dict does not conform to the schema

to_json(validate=True, ignore=[], context={}, indent=2, sort_keys=True, **kwargs)

Emit the JSON representation for this object as a string.

Parameters:
validate : boolean or string

If True (default), then validate the output dictionary against the schema. If “deep” then recursively validate all objects in the spec. This takes much more time, but it results in friendlier tracebacks for large objects.

ignore : list

A list of keys to ignore. This will not passed to child to_dict function calls.

context : dict (optional)

A context dictionary that will be passed to all child to_dict function calls

indent : integer, default 2

the number of spaces of indentation to use

sort_keys : boolean, default True

if True, sort keys in the output

**kwargs

Additional keyword arguments are passed to json.dumps()

Returns:
spec : string

The JSON specification of the chart object.

validate(instance, schema=None)

Validate the instance against the class schema in the context of the rootschema.

validate_property(name, value, schema=None)

Validate a property against property schema in the context of the rootschema