altair.Scale#
- class altair.Scale(align=Undefined, base=Undefined, bins=Undefined, clamp=Undefined, constant=Undefined, domain=Undefined, domainMax=Undefined, domainMid=Undefined, domainMin=Undefined, domainRaw=Undefined, exponent=Undefined, interpolate=Undefined, nice=Undefined, padding=Undefined, paddingInner=Undefined, paddingOuter=Undefined, range=Undefined, rangeMax=Undefined, rangeMin=Undefined, reverse=Undefined, round=Undefined, scheme=Undefined, type=Undefined, zero=Undefined, **kwds)#
Scale schema wrapper.
- Parameters:
- aligndict, float,
ExprRef The alignment of the steps within the scale range.
This value must lie in the range
[0,1]. A value of0.5indicates that the steps should be centered within the range. A value of0or1may be used to shift the bands to one side, say to position them adjacent to an axis.Default value:
0.5- basedict, float,
ExprRef The logarithm base of the
logscale (default10).- binsdict, Sequence[float],
ScaleBins,ScaleBinParams Bin boundaries can be provided to scales as either an explicit array of bin boundaries or as a bin specification object. The legal values are:
An array literal of bin boundary values. For example,
[0, 5, 10, 15, 20]. The array must include both starting and ending boundaries. The previous example uses five values to indicate a total of four bin intervals: [0-5), [5-10), [10-15), [15-20]. Array literals may include signal references as elements.A bin specification object that indicates the bin step size, and optionally the start and stop boundaries.
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.
- clampbool, dict,
ExprRef If
true, values that exceed the data domain are clamped to either the minimum or maximum range valueDefault value: derived from the scale config’s
clamp(trueby default).- constantdict, float,
ExprRef A constant determining the slope of the symlog function around zero. Only used for
symlogscales.Default value:
1- domaindict,
ExprRef, Literal[‘unaggregated’],DomainUnionWith,ParameterExtent, Sequence[str, bool, dict, float,ExprRef,DateTime, None] Customized domain values in the form of constant values or dynamic values driven by a parameter.
1) Constant
domainfor quantitative fields can take one of the following forms:A two-element array with minimum and maximum values. To create a diverging scale, this two-element array can be combined with the
domainMidproperty.An array with more than two entries, for Piecewise quantitative scales.
A string value
"unaggregated", if the input field is aggregated, to indicate that the domain should include the raw data values prior to the aggregation.
2) Constant
domainfor temporal fields can be a two-element array with minimum and maximum values, in the form of either timestamps or the DateTime definition objects.3) Constant
domainfor ordinal and nominal fields can be an array that lists valid input values.4) To combine (union) specified constant domain with the field’s values,
domaincan be an object with aunionWithproperty that specify constant domain to be combined. For example,domain: {unionWith: [0, 100]}for a quantitative scale means that the scale domain always includes[0, 100], but will include other values in the fields beyond[0, 100].5) Domain can also takes an object defining a field or encoding of a parameter that interactively determines the scale domain.
- domainMaxdict, float,
ExprRef,DateTime Sets the maximum value in the scale domain, overriding the
domainproperty. This property is only intended for use with scales having continuous domains.- domainMiddict, float,
ExprRef Inserts a single mid-point value into a two-element domain. The mid-point value must lie between the domain minimum and maximum values. This property can be useful for setting a midpoint for diverging color scales. The domainMid property is only intended for use with scales supporting continuous, piecewise domains.
- domainMindict, float,
ExprRef,DateTime Sets the minimum value in the scale domain, overriding the domain property. This property is only intended for use with scales having continuous domains.
- domainRawdict,
ExprRef An expression for an array of raw values that, if non-null, directly overrides the domain property. This is useful for supporting interactions such as panning or zooming a scale. The scale may be initially determined using a data-driven domain, then modified in response to user input by setting the rawDomain value.
- exponentdict, float,
ExprRef The exponent of the
powscale.- interpolatedict,
ExprRef,ScaleInterpolateEnum,ScaleInterpolateParams, Literal[‘rgb’, ‘lab’, ‘hcl’, ‘hsl’, ‘hsl-long’, ‘hcl-long’, ‘cubehelix’, ‘cubehelix-long’] 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,cubehelixandcubehelix-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
- nicebool, dict, float,
ExprRef,TimeInterval,TimeIntervalStep, Literal[‘millisecond’, ‘second’, ‘minute’, ‘hour’, ‘day’, ‘week’, ‘month’, ‘year’] 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,
nicecan be either a boolean flag or a number. Ifniceis 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
nicevalue can be a string indicating the desired time interval. Legal values are"millisecond","second","minute","hour","day","week","month", and"year". Alternatively,timeandutcscales 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:
truefor unbinned quantitative fields without explicit domain bounds;falseotherwise.- paddingdict, float,
ExprRef For `continuous <https://vega.github.io/vega-lite/docs/scale.html#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
zero,nice,domainMin, anddomainMaxproperties.For `band <https://vega.github.io/vega-lite/docs/scale.html#band>`__ scales, shortcut for setting
paddingInnerandpaddingOuterto the same value.For `point <https://vega.github.io/vega-lite/docs/scale.html#point>`__ scales, alias for
paddingOuter.Default value: For continuous scales, derived from the scale config’s
continuousPadding. For band and point scales, seepaddingInnerandpaddingOuter. By default, Vega-Lite sets padding such that width/height = number of unique values * step.- paddingInnerdict, float,
ExprRef 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.- paddingOuterdict, float,
ExprRef 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
bandPaddingOuterfor band scales andpointPaddingfor point scales. By default, Vega-Lite sets outer padding such that width/height = number of unique values * step.- rangedict,
RangeEnum,FieldRange, Sequence[str, dict, float, Sequence[float],ExprRef], Literal[‘width’, ‘height’, ‘symbol’, ‘category’, ‘ordinal’, ‘ramp’, ‘diverging’, ‘heatmap’] 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 or an object with a
fieldproperty representing the range values. For example, if a fieldcolorcontains CSS color names, we can setrangeto{field: "color"}.
Notes:
1) For color scales you can also specify a color scheme instead of
range.2) Any directly specified
rangeforxandychannels will be ignored. Range can be customized via the view’s corresponding size (widthandheight).- rangeMaxstr, dict, float,
ExprRef Sets the maximum value in the scale range, overriding the
rangeproperty or the default range. This property is only intended for use with scales having continuous ranges.- rangeMinstr, dict, float,
ExprRef Sets the minimum value in the scale range, overriding the
rangeproperty or the default range. This property is only intended for use with scales having continuous ranges.- reversebool, dict,
ExprRef If true, reverses the order of the scale range. Default value:
false.- roundbool, dict,
ExprRef If
true, rounds numeric output values to integers. This can be helpful for snapping to the pixel grid.Default value:
false.- schemedict,
ExprRef,Cyclical,Diverging,Categorical,ColorScheme,SchemeParams,SequentialMultiHue,SequentialSingleHue, Literal[‘accent’, ‘category10’, ‘category20’, ‘category20b’, ‘category20c’, ‘dark2’, ‘paired’, ‘pastel1’, ‘pastel2’, ‘set1’, ‘set2’, ‘set3’, ‘tableau10’, ‘tableau20’, ‘blueorange’, ‘blueorange-3’, ‘blueorange-4’, ‘blueorange-5’, ‘blueorange-6’, ‘blueorange-7’, ‘blueorange-8’, ‘blueorange-9’, ‘blueorange-10’, ‘blueorange-11’, ‘brownbluegreen’, ‘brownbluegreen-3’, ‘brownbluegreen-4’, ‘brownbluegreen-5’, ‘brownbluegreen-6’, ‘brownbluegreen-7’, ‘brownbluegreen-8’, ‘brownbluegreen-9’, ‘brownbluegreen-10’, ‘brownbluegreen-11’, ‘purplegreen’, ‘purplegreen-3’, ‘purplegreen-4’, ‘purplegreen-5’, ‘purplegreen-6’, ‘purplegreen-7’, ‘purplegreen-8’, ‘purplegreen-9’, ‘purplegreen-10’, ‘purplegreen-11’, ‘pinkyellowgreen’, ‘pinkyellowgreen-3’, ‘pinkyellowgreen-4’, ‘pinkyellowgreen-5’, ‘pinkyellowgreen-6’, ‘pinkyellowgreen-7’, ‘pinkyellowgreen-8’, ‘pinkyellowgreen-9’, ‘pinkyellowgreen-10’, ‘pinkyellowgreen-11’, ‘purpleorange’, ‘purpleorange-3’, ‘purpleorange-4’, ‘purpleorange-5’, ‘purpleorange-6’, ‘purpleorange-7’, ‘purpleorange-8’, ‘purpleorange-9’, ‘purpleorange-10’, ‘purpleorange-11’, ‘redblue’, ‘redblue-3’, ‘redblue-4’, ‘redblue-5’, ‘redblue-6’, ‘redblue-7’, ‘redblue-8’, ‘redblue-9’, ‘redblue-10’, ‘redblue-11’, ‘redgrey’, ‘redgrey-3’, ‘redgrey-4’, ‘redgrey-5’, ‘redgrey-6’, ‘redgrey-7’, ‘redgrey-8’, ‘redgrey-9’, ‘redgrey-10’, ‘redgrey-11’, ‘redyellowblue’, ‘redyellowblue-3’, ‘redyellowblue-4’, ‘redyellowblue-5’, ‘redyellowblue-6’, ‘redyellowblue-7’, ‘redyellowblue-8’, ‘redyellowblue-9’, ‘redyellowblue-10’, ‘redyellowblue-11’, ‘redyellowgreen’, ‘redyellowgreen-3’, ‘redyellowgreen-4’, ‘redyellowgreen-5’, ‘redyellowgreen-6’, ‘redyellowgreen-7’, ‘redyellowgreen-8’, ‘redyellowgreen-9’, ‘redyellowgreen-10’, ‘redyellowgreen-11’, ‘spectral’, ‘spectral-3’, ‘spectral-4’, ‘spectral-5’, ‘spectral-6’, ‘spectral-7’, ‘spectral-8’, ‘spectral-9’, ‘spectral-10’, ‘spectral-11’, ‘blues’, ‘tealblues’, ‘teals’, ‘greens’, ‘browns’, ‘greys’, ‘purples’, ‘warmgreys’, ‘reds’, ‘oranges’, ‘rainbow’, ‘sinebow’, ‘turbo’, ‘viridis’, ‘inferno’, ‘magma’, ‘plasma’, ‘cividis’, ‘bluegreen’, ‘bluegreen-3’, ‘bluegreen-4’, ‘bluegreen-5’, ‘bluegreen-6’, ‘bluegreen-7’, ‘bluegreen-8’, ‘bluegreen-9’, ‘bluepurple’, ‘bluepurple-3’, ‘bluepurple-4’, ‘bluepurple-5’, ‘bluepurple-6’, ‘bluepurple-7’, ‘bluepurple-8’, ‘bluepurple-9’, ‘goldgreen’, ‘goldgreen-3’, ‘goldgreen-4’, ‘goldgreen-5’, ‘goldgreen-6’, ‘goldgreen-7’, ‘goldgreen-8’, ‘goldgreen-9’, ‘goldorange’, ‘goldorange-3’, ‘goldorange-4’, ‘goldorange-5’, ‘goldorange-6’, ‘goldorange-7’, ‘goldorange-8’, ‘goldorange-9’, ‘goldred’, ‘goldred-3’, ‘goldred-4’, ‘goldred-5’, ‘goldred-6’, ‘goldred-7’, ‘goldred-8’, ‘goldred-9’, ‘greenblue’, ‘greenblue-3’, ‘greenblue-4’, ‘greenblue-5’, ‘greenblue-6’, ‘greenblue-7’, ‘greenblue-8’, ‘greenblue-9’, ‘orangered’, ‘orangered-3’, ‘orangered-4’, ‘orangered-5’, ‘orangered-6’, ‘orangered-7’, ‘orangered-8’, ‘orangered-9’, ‘purplebluegreen’, ‘purplebluegreen-3’, ‘purplebluegreen-4’, ‘purplebluegreen-5’, ‘purplebluegreen-6’, ‘purplebluegreen-7’, ‘purplebluegreen-8’, ‘purplebluegreen-9’, ‘purpleblue’, ‘purpleblue-3’, ‘purpleblue-4’, ‘purpleblue-5’, ‘purpleblue-6’, ‘purpleblue-7’, ‘purpleblue-8’, ‘purpleblue-9’, ‘purplered’, ‘purplered-3’, ‘purplered-4’, ‘purplered-5’, ‘purplered-6’, ‘purplered-7’, ‘purplered-8’, ‘purplered-9’, ‘redpurple’, ‘redpurple-3’, ‘redpurple-4’, ‘redpurple-5’, ‘redpurple-6’, ‘redpurple-7’, ‘redpurple-8’, ‘redpurple-9’, ‘yellowgreenblue’, ‘yellowgreenblue-3’, ‘yellowgreenblue-4’, ‘yellowgreenblue-5’, ‘yellowgreenblue-6’, ‘yellowgreenblue-7’, ‘yellowgreenblue-8’, ‘yellowgreenblue-9’, ‘yellowgreen’, ‘yellowgreen-3’, ‘yellowgreen-4’, ‘yellowgreen-5’, ‘yellowgreen-6’, ‘yellowgreen-7’, ‘yellowgreen-8’, ‘yellowgreen-9’, ‘yelloworangebrown’, ‘yelloworangebrown-3’, ‘yelloworangebrown-4’, ‘yelloworangebrown-5’, ‘yelloworangebrown-6’, ‘yelloworangebrown-7’, ‘yelloworangebrown-8’, ‘yelloworangebrown-9’, ‘yelloworangered’, ‘yelloworangered-3’, ‘yelloworangered-4’, ‘yelloworangered-5’, ‘yelloworangered-6’, ‘yelloworangered-7’, ‘yelloworangered-8’, ‘yelloworangered-9’, ‘darkblue’, ‘darkblue-3’, ‘darkblue-4’, ‘darkblue-5’, ‘darkblue-6’, ‘darkblue-7’, ‘darkblue-8’, ‘darkblue-9’, ‘darkgold’, ‘darkgold-3’, ‘darkgold-4’, ‘darkgold-5’, ‘darkgold-6’, ‘darkgold-7’, ‘darkgold-8’, ‘darkgold-9’, ‘darkgreen’, ‘darkgreen-3’, ‘darkgreen-4’, ‘darkgreen-5’, ‘darkgreen-6’, ‘darkgreen-7’, ‘darkgreen-8’, ‘darkgreen-9’, ‘darkmulti’, ‘darkmulti-3’, ‘darkmulti-4’, ‘darkmulti-5’, ‘darkmulti-6’, ‘darkmulti-7’, ‘darkmulti-8’, ‘darkmulti-9’, ‘darkred’, ‘darkred-3’, ‘darkred-4’, ‘darkred-5’, ‘darkred-6’, ‘darkred-7’, ‘darkred-8’, ‘darkred-9’, ‘lightgreyred’, ‘lightgreyred-3’, ‘lightgreyred-4’, ‘lightgreyred-5’, ‘lightgreyred-6’, ‘lightgreyred-7’, ‘lightgreyred-8’, ‘lightgreyred-9’, ‘lightgreyteal’, ‘lightgreyteal-3’, ‘lightgreyteal-4’, ‘lightgreyteal-5’, ‘lightgreyteal-6’, ‘lightgreyteal-7’, ‘lightgreyteal-8’, ‘lightgreyteal-9’, ‘lightmulti’, ‘lightmulti-3’, ‘lightmulti-4’, ‘lightmulti-5’, ‘lightmulti-6’, ‘lightmulti-7’, ‘lightmulti-8’, ‘lightmulti-9’, ‘lightorange’, ‘lightorange-3’, ‘lightorange-4’, ‘lightorange-5’, ‘lightorange-6’, ‘lightorange-7’, ‘lightorange-8’, ‘lightorange-9’, ‘lighttealblue’, ‘lighttealblue-3’, ‘lighttealblue-4’, ‘lighttealblue-5’, ‘lighttealblue-6’, ‘lighttealblue-7’, ‘lighttealblue-8’, ‘lighttealblue-9’] 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.
To set a custom scheme, instead set the list of values as the scale range.
For the full list of supported schemes, please refer to the Vega Scheme reference.
- type
ScaleType, Literal[‘linear’, ‘log’, ‘pow’, ‘sqrt’, ‘symlog’, ‘identity’, ‘sequential’, ‘time’, ‘utc’, ‘quantile’, ‘quantize’, ‘threshold’, ‘bin-ordinal’, ‘ordinal’, ‘point’, ‘band’] 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.
- zerobool, dict,
ExprRef If
true, ensures that a zero baseline value is included in the scale domain.Default value:
truefor x and y channels if the quantitative field is not binned and no customdomainis provided;falseotherwise.Note: Log, time, and utc scales do not support
zero.
- aligndict, float,
- __init__(align=Undefined, base=Undefined, bins=Undefined, clamp=Undefined, constant=Undefined, domain=Undefined, domainMax=Undefined, domainMid=Undefined, domainMin=Undefined, domainRaw=Undefined, exponent=Undefined, interpolate=Undefined, nice=Undefined, padding=Undefined, paddingInner=Undefined, paddingOuter=Undefined, range=Undefined, rangeMax=Undefined, rangeMin=Undefined, reverse=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])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, indent, sort_keys, ...])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 rootschema.