altair.Encoding¶
- 
class 
altair.Encoding(color=Undefined, detail=Undefined, fill=Undefined, fillOpacity=Undefined, href=Undefined, key=Undefined, latitude=Undefined, latitude2=Undefined, longitude=Undefined, longitude2=Undefined, opacity=Undefined, order=Undefined, shape=Undefined, size=Undefined, stroke=Undefined, strokeDash=Undefined, strokeOpacity=Undefined, strokeWidth=Undefined, text=Undefined, tooltip=Undefined, url=Undefined, x=Undefined, x2=Undefined, xError=Undefined, xError2=Undefined, y=Undefined, y2=Undefined, yError=Undefined, yError2=Undefined, **kwds)¶ Encoding schema wrapper
Mapping(required=[])
- Attributes
 - coloranyOf(
ColorGradientFieldDefWithCondition, - :class:`ColorGradientValueWithCondition`)
 Color of the marks – either fill or stroke color based on the
filledproperty of mark definition. By default,colorrepresents fill color for"area","bar","tick","text","trail","circle", and"square"/ stroke color for"line"and"point".Default value: If undefined, the default color depends on mark config ‘s
colorproperty.Note: 1) For fine-grained control over both fill and stroke colors of the marks, please use the
fillandstrokechannels. Thefillorstrokeencodings have higher precedence thancolor, thus may override thecolorencoding if conflicting encodings are specified. 2) See the scale documentation for more information about customizing color scheme.- detailanyOf(
FieldDefWithoutScale, List(FieldDefWithoutScale)) Additional levels of detail for grouping data in aggregate views and in line, trail, and area marks without mapping data to a specific visual channel.
- fillanyOf(
ColorGradientFieldDefWithCondition, - :class:`ColorGradientValueWithCondition`)
 Fill color of the marks. Default value: If undefined, the default color depends on mark config ‘s
colorproperty.Note: The
fillencoding has higher precedence thancolor, thus may override thecolorencoding if conflicting encodings are specified.- fillOpacityanyOf(
NumericFieldDefWithCondition, - :class:`NumericValueWithCondition`)
 Fill opacity of the marks.
Default value: If undefined, the default opacity depends on mark config ‘s
fillOpacityproperty.- hrefanyOf(
StringFieldDefWithCondition,StringValueWithCondition) A URL to load upon mouse click.
- key
FieldDefWithoutScale A data field to use as a unique key for data binding. When a visualization’s data is updated, the key value will be used to match data elements to existing mark instances. Use a key channel to enable object constancy for transitions over dynamic data.
- latitudeanyOf(
LatLongFieldDef,NumberValueDef) Latitude position of geographically projected marks.
- latitude2anyOf(
SecondaryFieldDef,NumberValueDef) Latitude-2 position for geographically projected ranged
"area","bar","rect", and"rule".- longitudeanyOf(
LatLongFieldDef,NumberValueDef) Longitude position of geographically projected marks.
- longitude2anyOf(
SecondaryFieldDef,NumberValueDef) Longitude-2 position for geographically projected ranged
"area","bar","rect", and"rule".- opacityanyOf(
NumericFieldDefWithCondition,NumericValueWithCondition) Opacity of the marks.
Default value: If undefined, the default opacity depends on mark config ‘s
opacityproperty.- orderanyOf(
OrderFieldDef, List(OrderFieldDef),NumberValueDef) Order of the marks.
For stacked marks, this
orderchannel encodes stack order.For line and trail marks, this
orderchannel encodes order of data points in the lines. This can be useful for creating a connected scatterplot. Settingorderto{"value": null}makes the line marks use the original order in the data sources.Otherwise, this
orderchannel encodes layer order of the marks.
Note : In aggregate plots,
orderfield should beaggregated to avoid creating additional aggregation grouping.- shapeanyOf(
ShapeFieldDefWithCondition,ShapeValueWithCondition) Shape of the mark.
#. For
pointmarks the supported values include:plotting shapes:
"circle","square","cross","diamond",
"triangle-up","triangle-down","triangle-right", or"triangle-left". * the line symbol"stroke"* centered directional shapes"arrow","wedge", or"triangle"* a custom SVG path string (For correct sizing, custom shape paths should be defined within a square bounding box with coordinates ranging from -1 to 1 along both the x and y dimensions.)#. For
geoshapemarks it should be a field definition of the geojson dataDefault value: If undefined, the default shape depends on mark config ‘s
shapeproperty. ("circle"if unset.)- sizeanyOf(
NumericFieldDefWithCondition,NumericValueWithCondition) Size of the mark.
For
"point","square"and"circle", – the symbol size, or pixel area of the mark.For
"bar"and"tick"– the bar and tick’s size.For
"text"– the text’s font size.Size is unsupported for
"line","area", and"rect". (Use"trail"instead of line with varying size)
- strokeanyOf(
ColorGradientFieldDefWithCondition, - :class:`ColorGradientValueWithCondition`)
 Stroke color of the marks. Default value: If undefined, the default color depends on mark config ‘s
colorproperty.Note: The
strokeencoding has higher precedence thancolor, thus may override thecolorencoding if conflicting encodings are specified.- strokeDashanyOf(
NumericArrayFieldDefWithCondition, - :class:`NumericArrayValueDefWithCondition`)
 Stroke dash of the marks.
Default value:
[1,0](No dash).- strokeOpacityanyOf(
NumericFieldDefWithCondition, - :class:`NumericValueWithCondition`)
 Stroke opacity of the marks.
Default value: If undefined, the default opacity depends on mark config ‘s
strokeOpacityproperty.- strokeWidthanyOf(
NumericFieldDefWithCondition, - :class:`NumericValueWithCondition`)
 Stroke width of the marks.
Default value: If undefined, the default stroke width depends on mark config ‘s
strokeWidthproperty.- textanyOf(
TextFieldDefWithCondition,TextValueWithCondition) Text of the
textmark.- tooltipanyOf(
StringFieldDefWithCondition,StringValueWithCondition, - List(:class:`StringFieldDef`), None)
 The tooltip text to show upon mouse hover. Specifying
tooltipencoding overrides the tooltip property in the mark definition.See the tooltip documentation for a detailed discussion about tooltip in Vega-Lite.
- urlanyOf(
StringFieldDefWithCondition,StringValueWithCondition) The URL of an image mark.
- xanyOf(
PositionFieldDef,XValueDef) X coordinates of the marks, or width of horizontal
"bar"and"area"without specifiedx2orwidth.The
valueof this channel can be a number or a string"width"for the width of the plot.- x2anyOf(
SecondaryFieldDef,XValueDef) X2 coordinates for ranged
"area","bar","rect", and"rule".The
valueof this channel can be a number or a string"width"for the width of the plot.- xErroranyOf(
SecondaryFieldDef,NumberValueDef) Error value of x coordinates for error specified
"errorbar"and"errorband".- xError2anyOf(
SecondaryFieldDef,NumberValueDef) Secondary error value of x coordinates for error specified
"errorbar"and"errorband".- yanyOf(
PositionFieldDef,YValueDef) Y coordinates of the marks, or height of vertical
"bar"and"area"without specifiedy2orheight.The
valueof this channel can be a number or a string"height"for the height of the plot.- y2anyOf(
SecondaryFieldDef,YValueDef) Y2 coordinates for ranged
"area","bar","rect", and"rule".The
valueof this channel can be a number or a string"height"for the height of the plot.- yErroranyOf(
SecondaryFieldDef,NumberValueDef) Error value of y coordinates for error specified
"errorbar"and"errorband".- yError2anyOf(
SecondaryFieldDef,NumberValueDef) Secondary error value of y coordinates for error specified
"errorbar"and"errorband".
- coloranyOf(
 
- 
__init__(self, color=Undefined, detail=Undefined, fill=Undefined, fillOpacity=Undefined, href=Undefined, key=Undefined, latitude=Undefined, latitude2=Undefined, longitude=Undefined, longitude2=Undefined, opacity=Undefined, order=Undefined, shape=Undefined, size=Undefined, stroke=Undefined, strokeDash=Undefined, strokeOpacity=Undefined, strokeWidth=Undefined, text=Undefined, tooltip=Undefined, url=Undefined, x=Undefined, x2=Undefined, xError=Undefined, xError2=Undefined, y=Undefined, y2=Undefined, yError=Undefined, yError2=Undefined, **kwds)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__(self[, color, detail, fill, …])Initialize self.
copy(self[, 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(self[, validate, ignore, context])Return a dictionary representation of the object
to_json(self[, validate, ignore, context, …])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
- 
copy(self, deep=True, ignore=())¶ Return a copy of the object
- Parameters
 - deepboolean 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.
- ignorelist, optional
 A list of keys for which the contents should not be copied, but only stored by reference.
- 
classmethod 
from_dict(dct, validate=True, _wrapper_classes=None)¶ Construct class from a dictionary representation
- Parameters
 - dctdictionary
 The dict from which to construct the class
- validateboolean
 If True (default), then validate the input against the schema.
- _wrapper_classeslist (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
 - objSchema object
 The wrapped schema
- Raises
 - jsonschema.ValidationError :
 if validate=True and dct does not conform to the schema
- 
classmethod 
from_json(json_string, validate=True, **kwargs)¶ Instantiate the object from a valid JSON string
- Parameters
 - json_stringstring
 The string containing a valid JSON chart specification.
- validateboolean
 If True (default), then validate the input against the schema.
- **kwargs :
 Additional keyword arguments are passed to json.loads
- Returns
 - chartChart object
 The altair Chart object built from the specification.
- 
classmethod 
resolve_references(schema=None)¶ Resolve references in the context of this object’s schema or root schema.
- 
to_dict(self, validate=True, ignore=None, context=None)¶ Return a dictionary representation of the object
- Parameters
 - validateboolean 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.
- ignorelist
 A list of keys to ignore. This will not passed to child to_dict function calls.
- contextdict (optional)
 A context dictionary that will be passed to all child to_dict function calls
- Returns
 - dctdictionary
 The dictionary representation of this object
- Raises
 - jsonschema.ValidationError :
 if validate=True and the dict does not conform to the schema
- 
to_json(self, validate=True, ignore=[], context={}, indent=2, sort_keys=True, **kwargs)¶ Emit the JSON representation for this object as a string.
- Parameters
 - validateboolean 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.
- ignorelist
 A list of keys to ignore. This will not passed to child to_dict function calls.
- contextdict (optional)
 A context dictionary that will be passed to all child to_dict function calls
- indentinteger, default 2
 the number of spaces of indentation to use
- sort_keysboolean, default True
 if True, sort keys in the output
- **kwargs
 Additional keyword arguments are passed to
json.dumps()
- Returns
 - specstring
 The JSON specification of the chart object.
- 
classmethod 
validate(instance, schema=None)¶ Validate the instance against the class schema in the context of the rootschema.
- 
classmethod 
validate_property(name, value, schema=None)¶ Validate a property against property schema in the context of the rootschema