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.
atob(string, /)bandspace(count[, paddingInner, paddingOuter])Returns the number of steps needed within a band scale, based on the
countof 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.
btoa(string, /)ceil(value, /)Rounds
valueto the nearest integer of equal or greater value.clamp(value, min, max, /)Restricts
valueto be between the specifiedminandmax.clampRange(range, min, max, /)Clamps a two-element
rangearray 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
undefinedif 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
valuefor a log-normal distribution with specified logmeanand log standard deviationstdev.cumulativeNormal(value[, mean, stdev])Returns the value of the cumulative distribution function at the given input domain
valuefor a normal distribution with specifiedmeanand standard deviationstdev.cumulativeUniform(value[, min, max])Returns the value of the cumulative distribution function at the given input domain
valuefor 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
datetimevalue, in local time.datetime(year, month[, day, hour, min, sec, ...])Returns a new
Dateinstance.day(datetime, /)Returns the day of the week for the given
datetimevalue, 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
datetimevalue, 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 logmeanand 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 specifiedmeanand 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, andNaNvalues.floor(value, /)Rounds
valueto the nearest integer of equal or lower value.format(value, specifier, /)Formats a numeric
valueas 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
featureaccording 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 pointsp0andp1, 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
datetimevalue, 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
testis truthy, returnsthenValue.inScope(item, /)Returns true if the given scenegraph
itemis 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
namecontains a datum with afieldvalue that matches the inputvalue.indexof(array, value, /)Returns the first index of
valuein the inputarray.info(value1[, value2])Logs an informative message and returns the last argument.
inrange(value, range, /)Tests whether
valuelies within (or is equal to either) the first and last values of therangearray.invert(name, value[, group])Inverts the named scale transform (or projection) for the specified
value.isArray(value, /)Returns true if
valueis an array, false otherwise.isBoolean(value, /)Returns true if
valueis a boolean (trueorfalse), false otherwise.isDate(value, /)Returns true if
valueis a Date object, false otherwise.isDefined(value, /)Returns true if
valueis a defined value, false ifvalueequalsundefined.isFinite(value, /)Returns true if
valueis a finite number.isNaN(value, /)Returns true if
valueis not a number.isNumber(value, /)Returns true if
valueis a number, false otherwise.isObject(value, /)Returns true if
valueis an object (including arrays and Dates), false otherwise.isRegExp(value, /)Returns true if
valueis a RegExp (regular expression) object, false otherwise.isString(value, /)Returns true if
valueis a string, false otherwise.isValid(value, /)Returns true if
valueis 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 specifiedseparatorstring.lab(*args)Constructs a new CIE LAB color.
lastindexof(array, value, /)Returns the last index of
valuein 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
arrayfor the provided interpolationfraction(typically between 0 and 1).log(value, /)Returns the natural logarithm of
value.lower(string, /)Transforms
stringto 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
datetimevalue, in local time.min(value1, value2, *args)Returns the minimum argument value.
minutes(datetime, /)Returns the minutes component for the given
datetimevalue, in local time.month(datetime, /)Returns the (zero-based) month for the given
datetimevalue, in local time.monthAbbrevFormat(month, /)Formats a (zero-based)
monthnumber as an abbreviated month name, according to the current locale.monthFormat(month, /)Formats a (zero-based)
monthnumber 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
stringvalue with repeated instances of acharacterup to a specifiedlength.panLinear(domain, delta, /)Given a linear scale
domainarray 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
domainarray 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
domainarray 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
domainarray 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
stringto a floating-point value.parseInt(string, /)Parses the input
stringto 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
fieldfrom a givenarrayof objects.pow(value, exponent, /)Returns
valueraised 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 logmeanand 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 specifiedmeanand 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
datetimevalue, 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
patternstring and optionalflags.replace(string, pattern, replacement, /)Returns a new string with some or all matches of
patternreplaced by areplacementstring.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
valueto the nearest integer.sampleLogNormal([mean, stdev])Returns a sample from a univariate log-normal probability distribution with specified log
meanand log standard deviationstdev.sampleNormal([mean, stdev])Returns a sample from a univariate normal (Gaussian) probability distribution with specified
meanand 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
datetimevalue, 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
arraybetween thestartandendindices.sort(array, /)Sorts the array in natural order using ascending from Vega Utils.
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
stringbetween thestartandendindices.tan(value, /)Trigonometric tangent.
test(regexp[, string])Evaluates a regular expression
regexpagainst the inputstring, returningtrueif the string matches the pattern,falseotherwise.time(datetime, /)Returns the epoch-based timestamp for the given
datetimevalue.timeFormat(value, specifier, /)Formats a datetime
value(either aDateobject or timestamp) as a string, according to the local time.timeOffset(unit, date[, step])Returns a new
Dateinstance that offsets the givendateby the specified time *unit* in the local timezone.timeParse(string, specifier, /)Parses a
stringvalue to a Date object, according to the local time.timeSequence(unit, start, stop[, step])Returns an array of
Dateinstances 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
datetimevalue.toBoolean(value, /)Coerces the input
valueto a string.toDate(value, /)Coerces the input
valueto a Date instance.toNumber(value, /)Coerces the input
valueto a number.toString(value, /)Coerces the input
valueto 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 thesourcenode id to thetargetnode id.trim(string, /)Returns a trimmed string with preceding and trailing whitespace removed.
truncate(string, length[, align, ellipsis])Truncates an input
stringto a targetlength.upper(string, /)Transforms
stringto 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 aDateobject or timestamp) as a string, according to UTC time.utcOffset(unit, date[, step])Returns a new
Dateinstance that offsets the givendateby 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
Dateinstances 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
datetimevalue, in UTC time.utcday(datetime, /)Returns the day of the week for the given
datetimevalue, in UTC time.utcdayofyear(datetime, /)Returns the one-based day of the year for the given
datetimevalue, in UTC time.utchours(datetime, /)Returns the hours component for the given
datetimevalue, in UTC time.utcmilliseconds(datetime, /)Returns the milliseconds component for the given
datetimevalue, in UTC time.utcminutes(datetime, /)Returns the minutes component for the given
datetimevalue, in UTC time.utcmonth(datetime, /)Returns the (zero-based) month for the given
datetimevalue, in UTC time.utcquarter(datetime, /)Returns the quarter of the year (0-3) for the given
datetimevalue, in UTC time.utcseconds(datetime, /)Returns the seconds component for the given
datetimevalue, 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
datetimevalue, 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
datetimevalue, in local time.zoomLinear(domain, anchor, scaleFactor, /)Given a linear scale
domainarray 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
domainarray 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
domainarray 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
domainarray 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.