altair.expr#

class altair.expr(expr)#

Utility providing constants and classmethods to construct expressions.

Expressions can be used to write basic formulas that enable custom interactions.

Alternatively, an inline expression may be defined via expr().

Parameters:
expr: str

A vega expression string.

Returns:
ExprRef

Examples

>>> import altair as alt
>>> bind_range = alt.binding_range(min=100, max=300, name="Slider value:  ")
>>> param_width = alt.param(bind=bind_range, name="param_width")
>>> param_color = alt.param(
...     expr=alt.expr.if_(param_width < 200, "red", "black"),
...     name="param_color",
... )
>>> y = alt.Y("yval").axis(titleColor=param_color)
>>> y
Y({
  axis: {'titleColor': Parameter('param_color', VariableParameter({
    expr: if((param_width < 200),'red','black'),
    name: 'param_color'
  }))},
  shorthand: 'yval'
})
__init__(expr=Undefined, **kwds)#

Methods

__init__([expr])

abs(*args)

Returns the absolute value of value.

acos(*args)

Trigonometric arccosine.

asin(*args)

Trigonometric arcsine.

atan(*args)

Trigonometric arctangent.

atan2(*args)

Returns the arctangent of dy / dx.

bandspace(*args)

Returns the number of steps needed within a band scale, based on the count of domain elements and the inner and outer padding values.

bandwidth(*args)

Returns the current band width for the named band scale transform, or zero if the scale is not found or is not a band scale.

ceil(*args)

Rounds value to the nearest integer of equal or greater value.

clamp(*args)

Restricts value to be between the specified min and max.

clampRange(*args)

Clamps a two-element range array in a span-preserving manner.

containerSize(*args)

Returns the current CSS box size ([el.clientWidth, el.clientHeight]) of the parent DOM element that contains the Vega view.

contrast(*args)

Returns the contrast ratio between the input color specifiers as a float between 1 and 21.

copy(*args)

Returns a copy (a new cloned instance) of the named scale transform of projection, or undefined if no scale or projection is found.

cos(*args)

Trigonometric cosine.

cumulativeLogNormal(*args)

Returns the value of the cumulative distribution function at the given input domain value for a log-normal distribution with specified log mean and log standard deviation stdev.

cumulativeNormal(*args)

Returns the value of the cumulative distribution function at the given input domain value for a normal distribution with specified mean and standard deviation stdev.

cumulativeUniform(*args)

Returns the value of the cumulative distribution function at the given input domain value for a uniform distribution over the interval [min, max].

data(*args)

Returns the array of data objects for the Vega data set with the given name.

date(*args)

Returns the day of the month for the given datetime value, in local time.

datetime(*args)

Returns a new Date instance.

day(*args)

Returns the day of the week for the given datetime value, in local time.

dayAbbrevFormat(*args)

Formats a (0-6) weekday number as an abbreviated week day name, according to the current locale.

dayFormat(*args)

Formats a (0-6) weekday number as a full week day name, according to the current locale.

dayofyear(*args)

Returns the one-based day of the year for the given datetime value, in local time.

debug(*args)

Logs a debugging message and returns the last argument.

densityLogNormal(*args)

Returns the value of the probability density function at the given input domain value, for a log-normal distribution with specified log mean and log standard deviation stdev.

densityNormal(*args)

Returns the value of the probability density function at the given input domain value, for a normal distribution with specified mean and standard deviation stdev.

densityUniform(*args)

Returns the value of the probability density function at the given input domain value, for a uniform distribution over the interval [min, max].

domain(*args)

Returns the scale domain array for the named scale transform, or an empty array if the scale is not found.

exp(*args)

Returns the value of e raised to the provided exponent.

extent(*args)

Returns a new [min, max] array with the minimum and maximum values of the input array, ignoring null, undefined, and NaN values.

floor(*args)

Rounds value to the nearest integer of equal or lower value.

format(*args)

Formats a numeric value as a string.

from_dict(dct[, validate])

Construct class from a dictionary representation.

from_json(json_string[, validate])

Instantiate the object from a valid JSON string.

geoArea(*args)

Returns the projected planar area (typically in square pixels) of a GeoJSON feature according to the named projection.

geoBounds(*args)

Returns the projected planar bounding box (typically in pixels) for the specified GeoJSON feature, according to the named projection.

geoCentroid(*args)

Returns the projected planar centroid (typically in pixels) for the specified GeoJSON feature, according to the named projection.

gradient(*args)

Returns a linear color gradient for the scale (whose range must be a continuous color scheme and starting and ending points p0 and p1, each an [x, y] array.

group(*args)

Returns the scenegraph group mark item in which the current event has occurred.

hcl(*args)

Constructs a new HCL (hue, chroma, luminance) color.

hours(*args)

Returns the hours component for the given datetime value, in local time.

hsl(*args)

Constructs a new HSL color.

hypot(*args)

Returns the square root of the sum of squares of its arguments.

if_(*args)

If test is truthy, returns thenValue.

inScope(*args)

Returns true if the given scenegraph item is a descendant of the group mark in which the event handler was defined, false otherwise.

indata(*args)

Tests if the data set with a given name contains a datum with a field value that matches the input value.

indexof(*args)

Returns the first index of value in the input array, or the first index of substring in the input string.

info(*args)

Logs an informative message and returns the last argument.

inrange(*args)

Tests whether value lies within (or is equal to either) the first and last values of the range array.

invert(*args)

Inverts the named scale transform (or projection) for the specified value.

isArray(*args)

Returns true if value is an array, false otherwise.

isBoolean(*args)

Returns true if value is a boolean (true or false), false otherwise.

isDate(*args)

Returns true if value is a Date object, false otherwise.

isDefined(*args)

Returns true if value is a defined value, false if value equals undefined.

isFinite(*args)

Returns true if value is a finite number.

isNaN(*args)

Returns true if value is not a number.

isNumber(*args)

Returns true if value is a number, false otherwise.

isObject(*args)

Returns true if value is an object (including arrays and Dates), false otherwise.

isRegExp(*args)

Returns true if value is a RegExp (regular expression) object, false otherwise.

isString(*args)

Returns true if value is a string, false otherwise.

isValid(*args)

Returns true if value is not null, undefined, or NaN, false otherwise.

item(*args)

Returns the current scenegraph item that is the target of the event.

join(*args)

Returns a new string by concatenating all of the elements of the input array, separated by commas or a specified separator string.

lab(*args)

Constructs a new CIE LAB color.

lastindexof(*args)

Returns the last index of value in the input array, or the last index of substring in the input string.

length(*args)

Returns the length of the input array, or the length of the input string.

lerp(*args)

Returns the linearly interpolated value between the first and last entries in the array for the provided interpolation fraction (typically between 0 and 1).

log(*args)

Returns the natural logarithm of value.

lower(*args)

Transforms string to lower-case letters.

luminance(*args)

Returns the luminance for the given color specifier (compatible with d3-color's rgb function.

max(*args)

Returns the maximum argument value.

merge(*args)

Merges the input objects object1, object2, etc into a new output object.

milliseconds(*args)

Returns the milliseconds component for the given datetime value, in local time.

min(*args)

Returns the minimum argument value.

minutes(*args)

Returns the minutes component for the given datetime value, in local time.

month(*args)

Returns the (zero-based) month for the given datetime value, in local time.

monthAbbrevFormat(*args)

Formats a (zero-based) month number as an abbreviated month name, according to the current locale.

monthFormat(*args)

Formats a (zero-based) month number as a full month name, according to the current locale.

now(*args)

Returns the timestamp for the current time.

pad(*args)

Pads a string value with repeated instances of a character up to a specified length.

panLinear(*args)

Given a linear scale domain array with numeric or datetime values, returns a new two-element domain array that is the result of panning the domain by a fractional delta.

panLog(*args)

Given a log scale domain array with numeric or datetime values, returns a new two-element domain array that is the result of panning the domain by a fractional delta.

panPow(*args)

Given a power scale domain array with numeric or datetime values and the given exponent, returns a new two-element domain array that is the result of panning the domain by a fractional delta.

panSymlog(*args)

Given a symmetric log scale domain array with numeric or datetime values parameterized by the given constant, returns a new two-element domain array that is the result of panning the domain by a fractional delta.

parseFloat(*args)

Parses the input string to a floating-point value.

parseInt(*args)

Parses the input string to an integer value.

peek(*args)

Returns the last element in the input array.

pinchAngle(*args)

Returns the angle of the line connecting the first two touch points of a multi-touch event.

pinchDistance(*args)

Returns the pixel distance between the first two touch points of a multi-touch event.

pluck(*args)

Retrieves the value for the specified field from a given array of objects.

pow(*args)

Returns value raised to the given exponent.

quantileLogNormal(*args)

Returns the quantile value (the inverse of the cumulative distribution function for the given input probability, for a log-normal distribution with specified log mean and log standard deviation stdev.

quantileNormal(*args)

Returns the quantile value (the inverse of the cumulative distribution function for the given input probability, for a normal distribution with specified mean and standard deviation stdev.

quantileUniform(*args)

Returns the quantile value (the inverse of the cumulative distribution function for the given input probability, for a uniform distribution over the interval [min, max].

quarter(*args)

Returns the quarter of the year (0-3) for the given datetime value, in local time.

random(*args)

Returns a pseudo-random number in the range [0, 1].

range(*args)

Returns the scale range array for the named scale transform, or an empty array if the scale is not found.

regexp(*args)

Creates a regular expression instance from an input pattern string and optional flags.

replace(*args)

Returns a new string with some or all matches of pattern replaced by a replacement string.

resolve_references([schema])

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

reverse(*args)

Returns a new array with elements in a reverse order of the input array.

rgb(*args)

Constructs a new RGB color.

round(*args)

Rounds value to the nearest integer.

sampleLogNormal(*args)

Returns a sample from a univariate log-normal probability distribution with specified log mean and log standard deviation stdev.

sampleNormal(*args)

Returns a sample from a univariate normal (Gaussian) probability distribution with specified mean and standard deviation stdev.

sampleUniform(*args)

Returns a sample from a univariate continuous uniform probability distribution over the interval [min, max].

scale(*args)

Applies the named scale transform (or projection) to the specified value.

screen(*args)

Returns the window.screen object, or {} if Vega is not running in a browser environment.

seconds(*args)

Returns the seconds component for the given datetime value, in local time.

sequence(*args)

Returns an array containing an arithmetic sequence of numbers.

sin(*args)

Trigonometric sine.

slice(*args)

Returns a section of array between the start and end indices.

span(*args)

Returns the span of array: the difference between the last and first elements, or array[array.length-1] - array[0].

split(*args)

Returns an array of tokens created by splitting the input string according to a provided separator pattern.

sqrt(*args)

Square root function.

substring(*args)

Returns a section of string between the start and end indices.

tan(*args)

Trigonometric tangent.

test(*args)

Evaluates a regular expression regexp against the input string, returning true if the string matches the pattern, false otherwise.

time(*args)

Returns the epoch-based timestamp for the given datetime value.

timeFormat(*args)

Formats a datetime value (either a Date object or timestamp) as a string, according to the local time.

timeOffset(*args)

Returns a new Date instance that offsets the given date by the specified time unit in the local timezone.

timeParse(*args)

Parses a string value to a Date object, according to the local time.

timeSequence(*args)

Returns an array of Date instances from start (inclusive) to stop (exclusive), with each entry separated by the given time unit in the local timezone.

timeUnitSpecifier(*args)

Returns a time format specifier string for the given time unit.

timezoneoffset(*args)

Returns the timezone offset from the local timezone to UTC for the given datetime value.

toBoolean(*args)

Coerces the input value to a string.

toDate(*args)

Coerces the input value to a Date instance.

toNumber(*args)

Coerces the input value to a number.

toString(*args)

Coerces the input value to a string.

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.

treeAncestors(*args)

For the hierarchy data set with the given name, returns the array of ancestors nodes, starting with the input node, then followed by each parent up to the root.

treePath(*args)

For the hierarchy data set with the given name, returns the shortest path through from the source node id to the target node id.

trim(*args)

Returns a trimmed string with preceding and trailing whitespace removed.

truncate(*args)

Truncates an input string to a target length.

upper(*args)

Transforms string to upper-case letters.

utc(*args)

Returns a timestamp for the given UTC date.

utcFormat(*args)

Formats a datetime value (either a Date object or timestamp) as a string, according to UTC time.

utcOffset(*args)

Returns a new Date instance that offsets the given date by the specified time unit in UTC time.

utcParse(*args)

Parses a string value to a Date object, according to UTC time.

utcSequence(*args)

Returns an array of Date instances from start (inclusive) to stop (exclusive), with each entry separated by the given time unit in UTC time.

utcdate(*args)

Returns the day of the month for the given datetime value, in UTC time.

utcday(*args)

Returns the day of the week for the given datetime value, in UTC time.

utcdayofyear(*args)

Returns the one-based day of the year for the given datetime value, in UTC time.

utchours(*args)

Returns the hours component for the given datetime value, in UTC time.

utcmilliseconds(*args)

Returns the milliseconds component for the given datetime value, in UTC time.

utcminutes(*args)

Returns the minutes component for the given datetime value, in UTC time.

utcmonth(*args)

Returns the (zero-based) month for the given datetime value, in UTC time.

utcquarter(*args)

Returns the quarter of the year (0-3) for the given datetime value, in UTC time.

utcseconds(*args)

Returns the seconds component for the given datetime value, in UTC time.

utcweek(*args)

Returns the week number of the year for the given datetime, in UTC time.

utcyear(*args)

Returns the year for the given datetime value, in UTC time.

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.

warn(*args)

Logs a warning message and returns the last argument.

week(*args)

Returns the week number of the year for the given datetime, in local time.

windowSize(*args)

Returns the current window size ([window.innerWidth, window.innerHeight]) or [undefined, undefined] if Vega is not running in a browser environment.

x(*args)

Returns the x coordinate for the current event.

xy(*args)

Returns the x- and y-coordinates for the current event as a two-element array.

y(*args)

Returns the y coordinate for the current event.

year(*args)

Returns the year for the given datetime value, in local time.

zoomLinear(*args)

Given a linear scale domain array with numeric or datetime values, returns a new two-element domain array that is the result of zooming the domain by a scaleFactor, centered at the provided fractional anchor.

zoomLog(*args)

Given a log scale domain array with numeric or datetime values, returns a new two-element domain array that is the result of zooming the domain by a scaleFactor, centered at the provided fractional anchor.

zoomPow(*args)

Given a power scale domain array with numeric or datetime values and the given exponent, returns a new two-element domain array that is the result of zooming the domain by a scaleFactor, centered at the provided fractional anchor.

zoomSymlog(*args)

Given a symmetric log scale domain array with numeric or datetime values parameterized by the given constant, returns a new two-element domain array that is the result of zooming the domain by a scaleFactor, centered at the provided fractional anchor.