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
(value, /)Returns the absolute value of
value
.acos
(value, /)Trigonometric arccosine.
asin
(value, /)Trigonometric arcsine.
atan
(value, /)Trigonometric arctangent.
atan2
(dy, dx, /)Returns the arctangent of dy / dx.
bandspace
(count[, paddingInner, paddingOuter])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
(name[, group])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
(value, /)Rounds
value
to the nearest integer of equal or greater value.clamp
(value, min, max, /)Restricts
value
to be between the specifiedmin
andmax
.clampRange
(range, min, max, /)Clamps a two-element
range
array in a span-preserving manner.containerSize
()Returns the current CSS box size (
[el.clientWidth, el.clientHeight]
) of the parent DOM element that contains the Vega view.contrast
(specifier1, specifier2, /)Returns the contrast ratio between the input color specifiers as a float between 1 and 21.
copy
(name[, group])Returns a copy (a new cloned instance) of the named scale transform of projection, or
undefined
if no scale or projection is found.cos
(value, /)Trigonometric cosine.
cumulativeLogNormal
(value[, mean, stdev])Returns the value of the cumulative distribution function at the given input domain
value
for a log-normal distribution with specified logmean
and log standard deviationstdev
.cumulativeNormal
(value[, mean, stdev])Returns the value of the cumulative distribution function at the given input domain
value
for a normal distribution with specifiedmean
and standard deviationstdev
.cumulativeUniform
(value[, min, max])Returns the value of the cumulative distribution function at the given input domain
value
for a uniform distribution over the interval [min
,max
).data
(name, /)Returns the array of data objects for the Vega data set with the given
name
.date
(datetime, /)Returns the day of the month for the given
datetime
value, in local time.datetime
(year, month[, day, hour, min, sec, ...])Returns a new
Date
instance.day
(datetime, /)Returns the day of the week for the given
datetime
value, in local time.dayAbbrevFormat
(day, /)Formats a (0-6) weekday number as an abbreviated week day name, according to the current locale.
dayFormat
(day, /)Formats a (0-6) weekday number as a full week day name, according to the current locale.
dayofyear
(datetime, /)Returns the one-based day of the year for the given
datetime
value, in local time.debug
(value1[, value2])Logs a debugging message and returns the last argument.
densityLogNormal
(value[, mean, stdev])Returns the value of the probability density function at the given input domain
value
, for a log-normal distribution with specified logmean
and log standard deviationstdev
.densityNormal
(value[, mean, stdev])Returns the value of the probability density function at the given input domain
value
, for a normal distribution with specifiedmean
and standard deviationstdev
.densityUniform
(value[, min, max])Returns the value of the probability density function at the given input domain
value
, for a uniform distribution over the interval [min
,max
).domain
(name[, group])Returns the scale domain array for the named scale transform, or an empty array if the scale is not found.
exp
(exponent, /)Returns the value of e raised to the provided
exponent
.extent
(array, /)Returns a new [min, max] array with the minimum and maximum values of the input array, ignoring
null
,undefined
, andNaN
values.floor
(value, /)Rounds
value
to the nearest integer of equal or lower value.format
(value, specifier, /)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
(projection, feature[, group])Returns the projected planar area (typically in square pixels) of a GeoJSON
feature
according to the namedprojection
.geoBounds
(projection, feature[, group])Returns the projected planar bounding box (typically in pixels) for the specified GeoJSON
feature
, according to the namedprojection
.geoCentroid
(projection, feature[, group])Returns the projected planar centroid (typically in pixels) for the specified GeoJSON
feature
, according to the namedprojection
.geoScale
(projection[, group])Returns the scale value for the named
projection
.gradient
(scale, p0, p1[, count])Returns a linear color gradient for the
scale
(whose range must be a continuous color scheme) and starting and ending pointsp0
andp1
, each an [x, y] array.group
([name])Returns the scenegraph group mark item in which the current event has occurred.
hcl
(*args)Constructs a new HCL (hue, chroma, luminance) color.
hours
(datetime, /)Returns the hours component for the given
datetime
value, in local time.hsl
(*args)Constructs a new HSL color.
hypot
(value, /)Returns the square root of the sum of squares of its arguments.
if_
(test, thenValue, elseValue, /)If
test
is truthy, returnsthenValue
.inScope
(item, /)Returns true if the given scenegraph
item
is a descendant of the group mark in which the event handler was defined, false otherwise.indata
(name, field, value, /)Tests if the data set with a given
name
contains a datum with afield
value that matches the inputvalue
.indexof
(array, value, /)Returns the first index of
value
in the inputarray
.info
(value1[, value2])Logs an informative message and returns the last argument.
inrange
(value, range, /)Tests whether
value
lies within (or is equal to either) the first and last values of therange
array.invert
(name, value[, group])Inverts the named scale transform (or projection) for the specified
value
.isArray
(value, /)Returns true if
value
is an array, false otherwise.isBoolean
(value, /)Returns true if
value
is a boolean (true
orfalse
), false otherwise.isDate
(value, /)Returns true if
value
is a Date object, false otherwise.isDefined
(value, /)Returns true if
value
is a defined value, false ifvalue
equalsundefined
.isFinite
(value, /)Returns true if
value
is a finite number.isNaN
(value, /)Returns true if
value
is not a number.isNumber
(value, /)Returns true if
value
is a number, false otherwise.isObject
(value, /)Returns true if
value
is an object (including arrays and Dates), false otherwise.isRegExp
(value, /)Returns true if
value
is a RegExp (regular expression) object, false otherwise.isString
(value, /)Returns true if
value
is a string, false otherwise.isValid
(value, /)Returns true if
value
is notnull
,undefined
, orNaN
, false otherwise.item
()Returns the current scenegraph item that is the target of the event.
join
(array[, separator])Returns a new string by concatenating all of the elements of the input
array
, separated by commas or a specifiedseparator
string.lab
(*args)Constructs a new CIE LAB color.
lastindexof
(array, value, /)Returns the last index of
value
in the inputarray
.length
(array, /)Returns the length of the input
array
.lerp
(array, fraction, /)Returns the linearly interpolated value between the first and last entries in the
array
for the provided interpolationfraction
(typically between 0 and 1).log
(value, /)Returns the natural logarithm of
value
.lower
(string, /)Transforms
string
to lower-case letters.luminance
(specifier, /)Returns the luminance for the given color
specifier
(compatible with d3-color's rgb function).max
(value1, value2, *args)Returns the maximum argument value.
merge
(object1[, object2])Merges the input objects
object1
,object2
, etc into a new output object.milliseconds
(datetime, /)Returns the milliseconds component for the given
datetime
value, in local time.min
(value1, value2, *args)Returns the minimum argument value.
minutes
(datetime, /)Returns the minutes component for the given
datetime
value, in local time.month
(datetime, /)Returns the (zero-based) month for the given
datetime
value, in local time.monthAbbrevFormat
(month, /)Formats a (zero-based)
month
number as an abbreviated month name, according to the current locale.monthFormat
(month, /)Formats a (zero-based)
month
number as a full month name, according to the current locale.now
()Returns the timestamp for the current time.
pad
(string, length[, character, align])Pads a
string
value with repeated instances of acharacter
up to a specifiedlength
.panLinear
(domain, delta, /)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 fractionaldelta
.panLog
(domain, delta, /)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 fractionaldelta
.panPow
(domain, delta, exponent, /)Given a power scale
domain
array with numeric or datetime values and the givenexponent
, returns a new two-element domain array that is the result of panning the domain by a fractionaldelta
.panSymlog
(domain, delta, constant, /)Given a symmetric log scale
domain
array with numeric or datetime values parameterized by the givenconstant
, returns a new two-element domain array that is the result of panning the domain by a fractionaldelta
.parseFloat
(string, /)Parses the input
string
to a floating-point value.parseInt
(string, /)Parses the input
string
to an integer value.peek
(array, /)Returns the last element in the input
array
.pinchAngle
(event, /)Returns the angle of the line connecting the first two touch points of a multi-touch event.
pinchDistance
(event, /)Returns the pixel distance between the first two touch points of a multi-touch event.
pluck
(array, field, /)Retrieves the value for the specified
field
from a givenarray
of objects.pow
(value, exponent, /)Returns
value
raised to the givenexponent
.quantileLogNormal
(probability[, mean, stdev])Returns the quantile value (the inverse of the cumulative distribution function) for the given input
probability
, for a log-normal distribution with specified logmean
and log standard deviationstdev
.quantileNormal
(probability[, mean, stdev])Returns the quantile value (the inverse of the cumulative distribution function) for the given input
probability
, for a normal distribution with specifiedmean
and standard deviationstdev
.quantileUniform
(probability[, min, max])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
(datetime, /)Returns the quarter of the year (0-3) for the given
datetime
value, in local time.random
()Returns a pseudo-random number in the range [0,1).
range
(name[, group])Returns the scale range array for the named scale transform, or an empty array if the scale is not found.
regexp
(pattern[, flags])Creates a regular expression instance from an input
pattern
string and optionalflags
.replace
(string, pattern, replacement, /)Returns a new string with some or all matches of
pattern
replaced by areplacement
string.resolve_references
([schema])Resolve references in the context of this object's schema or root schema.
reverse
(array, /)Returns a new array with elements in a reverse order of the input
array
.rgb
(*args)Constructs a new RGB color.
round
(value, /)Rounds
value
to the nearest integer.sampleLogNormal
([mean, stdev])Returns a sample from a univariate log-normal probability distribution with specified log
mean
and log standard deviationstdev
.sampleNormal
([mean, stdev])Returns a sample from a univariate normal (Gaussian) probability distribution with specified
mean
and standard deviationstdev
.sampleUniform
([min, max])Returns a sample from a univariate continuous uniform probability distribution over the interval [
min
,max
).scale
(name, value[, group])Applies the named scale transform (or projection) to the specified
value
.screen
()Returns the window.screen object, or
{}
if Vega is not running in a browser environment.seconds
(datetime, /)Returns the seconds component for the given
datetime
value, in local time.sequence
(*args)Returns an array containing an arithmetic sequence of numbers.
sin
(value, /)Trigonometric sine.
slice
(array, start[, end])Returns a section of
array
between thestart
andend
indices.span
(array, /)Returns the span of
array
: the difference between the last and first elements, or array[array.length-1] - array[0].sqrt
(value, /)Square root function.
substring
(string, start[, end])Returns a section of
string
between thestart
andend
indices.tan
(value, /)Trigonometric tangent.
test
(regexp[, string])Evaluates a regular expression
regexp
against the inputstring
, returningtrue
if the string matches the pattern,false
otherwise.time
(datetime, /)Returns the epoch-based timestamp for the given
datetime
value.timeFormat
(value, specifier, /)Formats a datetime
value
(either aDate
object or timestamp) as a string, according to the local time.timeOffset
(unit, date[, step])Returns a new
Date
instance that offsets the givendate
by the specified time *unit* in the local timezone.timeParse
(string, specifier, /)Parses a
string
value to a Date object, according to the local time.timeSequence
(unit, start, stop[, step])Returns an array of
Date
instances fromstart
(inclusive) tostop
(exclusive), with each entry separated by the given time *unit* in the local timezone.timeUnitSpecifier
(units[, specifiers])Returns a time format specifier string for the given time *units*.
timezoneoffset
(datetime, /)Returns the timezone offset from the local timezone to UTC for the given
datetime
value.toBoolean
(value, /)Coerces the input
value
to a string.toDate
(value, /)Coerces the input
value
to a Date instance.toNumber
(value, /)Coerces the input
value
to a number.toString
(value, /)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
(name, node, /)For the hierarchy data set with the given
name
, returns the array of ancestors nodes, starting with the inputnode
, then followed by each parent up to the root.treePath
(name, source, target, /)For the hierarchy data set with the given
name
, returns the shortest path through from thesource
node id to thetarget
node id.trim
(string, /)Returns a trimmed string with preceding and trailing whitespace removed.
truncate
(string, length[, align, ellipsis])Truncates an input
string
to a targetlength
.upper
(string, /)Transforms
string
to upper-case letters.utc
(year, month[, day, hour, min, sec, millisec])Returns a timestamp for the given UTC date.
utcFormat
(value, specifier, /)Formats a datetime
value
(either aDate
object or timestamp) as a string, according to UTC time.utcOffset
(unit, date[, step])Returns a new
Date
instance that offsets the givendate
by the specified time *unit* in UTC time.utcParse
(value, specifier, /)Parses a string value to a Date object, according to UTC time.
utcSequence
(unit, start, stop[, step])Returns an array of
Date
instances fromstart
(inclusive) tostop
(exclusive), with each entry separated by the given time *unit* in UTC time.utcdate
(datetime, /)Returns the day of the month for the given
datetime
value, in UTC time.utcday
(datetime, /)Returns the day of the week for the given
datetime
value, in UTC time.utcdayofyear
(datetime, /)Returns the one-based day of the year for the given
datetime
value, in UTC time.utchours
(datetime, /)Returns the hours component for the given
datetime
value, in UTC time.utcmilliseconds
(datetime, /)Returns the milliseconds component for the given
datetime
value, in UTC time.utcminutes
(datetime, /)Returns the minutes component for the given
datetime
value, in UTC time.utcmonth
(datetime, /)Returns the (zero-based) month for the given
datetime
value, in UTC time.utcquarter
(datetime, /)Returns the quarter of the year (0-3) for the given
datetime
value, in UTC time.utcseconds
(datetime, /)Returns the seconds component for the given
datetime
value, in UTC time.utcweek
(date, /)Returns the week number of the year for the given datetime, in UTC time.
utcyear
(datetime, /)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
(value1[, value2])Logs a warning message and returns the last argument.
week
(date, /)Returns the week number of the year for the given datetime, in local time.
windowSize
()Returns the current window size (
[window.innerWidth, window.innerHeight]
) or[undefined, undefined]
if Vega is not running in a browser environment.x
([item])Returns the x coordinate for the current event.
xy
([item])Returns the x- and y-coordinates for the current event as a two-element array.
y
([item])Returns the y coordinate for the current event.
year
(datetime, /)Returns the year for the given
datetime
value, in local time.zoomLinear
(domain, anchor, scaleFactor, /)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 ascaleFactor
, centered at the provided fractionalanchor
.zoomLog
(domain, anchor, scaleFactor, /)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 ascaleFactor
, centered at the provided fractionalanchor
.zoomPow
(domain, anchor, scaleFactor, exponent, /)Given a power scale
domain
array with numeric or datetime values and the givenexponent
, returns a new two-element domain array that is the result of zooming the domain by ascaleFactor
, centered at the provided fractionalanchor
.zoomSymlog
(domain, anchor, scaleFactor, ...)Given a symmetric log scale
domain
array with numeric or datetime values parameterized by the givenconstant
, returns a new two-element domain array that is the result of zooming the domain by ascaleFactor
, centered at the provided fractionalanchor
.