Axis
Edit this pageAxes provide axis lines, ticks, and labels to convey how a positional range represents a data range. Simply put, axes visualize scales.
By default, Vega-Lite automatically creates axes with default properties for x
and y
channels when they encode data fields. User can set the axis
property of x- or y-field definition to an object to customize axis properties or set axis
to null
to remove the axis.
Besides axis
property of a field definition, the configuration object (config
) also provides axis config (config: {axis: {...}}
) for setting default axis properties for all axes.
Documentation Overview
- Axis Properties
- Axis Config
Axis Properties
// A Single View or a Layer Specification
{
...,
"mark/layer": ...,
"encoding": {
"x": {
"field": ...,
"type": ...,
"axis": { // Axis
...
},
...
},
"y": ...,
...
}
}
To customize axis, you can specify an axis
object in an encoding channel’s definition. This section lists all properties of axes.
See also: This interactive article demonstrates axes and legends in the underlying Vega language.
General
Property | Type | Description |
---|---|---|
aria | Boolean | ExprRef |
A boolean flag indicating if ARIA attributes should be included (SVG output only). If Default value: |
bandPosition | Number | ExprRef |
An interpolation fraction indicating where, for Default value: |
description | String | ExprRef |
A text description of this axis for ARIA accessibility (SVG output only). If the |
maxExtent | Number | ExprRef |
The maximum extent in pixels that axis ticks and labels should use. This determines a maximum offset value for axis titles. Default value: |
minExtent | Number | ExprRef |
The minimum extent in pixels that axis ticks and labels should use. This determines a minimum offset value for axis titles. Default value: |
orient | String | ExprRef |
The orientation of the axis. One of Default value: |
offset | Number |
The offset, in pixels, by which to displace the axis from the edge of the enclosing group or data rectangle. Default value: derived from the axis config’s |
position | Number | ExprRef |
The anchor position of the axis in pixels. For x-axes with top or bottom orientation, this sets the axis group x coordinate. For y-axes with left or right orientation, this sets the axis group y coordinate. Default value: |
style | String | String[] |
A string or array of strings indicating the name of custom styles to apply to the axis. A style is a named collection of axis property defined within the style configuration. If style is an array, later styles will override earlier styles. Default value: (none) Note: Any specified style will augment the default style. For example, an x-axis mark with |
translate | Number | ExprRef |
Coordinate space translation offset for axis layout. By default, axes are translated by a 0.5 pixel offset for both the x and y coordinates in order to align stroked lines with the pixel grid. However, for vector graphics output these pixel-specific adjustments may be undesirable, in which case translate can be changed (for example, to zero). Default value: |
zindex | Number |
A non-negative integer indicating the z-index of the axis. If zindex is 0, axes should be drawn behind all chart elements. To put them in front, set Default value: |
Example: Using Axis minExtent
to Align Multi-View Plots
By default, Vega-Lite automatically sets the axis extent (the space axis ticks and labels use). However, to align axes between multiple plots in multi-view displays, you can manually set minExtent
(and optionally maxExtent
) to make the extent consistent across plots.
Domain
Property | Type | Description |
---|---|---|
domain | Boolean | ExprRef |
A boolean flag indicating if the domain (the axis baseline) should be included as part of the axis. Default value: |
domainCap | String | ExprRef |
The stroke cap for the domain line’s ending style. One of Default value: |
domainColor | Null | Color | ExprRef |
Color of axis domain line. Default value: |
domainOpacity | Number | ExprRef |
Opacity of the axis domain line. |
domainWidth | Number | ExprRef |
Stroke width of axis domain line Default value: |
domainDash | Number[] | ExprRef |
An array of alternating [stroke, space] lengths for dashed domain lines. |
domainDashOffset | Number | ExprRef |
The pixel offset at which to start drawing with the domain dash array. |
Labels
Property | Type | Description |
---|---|---|
format | String | Dict |
When used with the default
See the format documentation for more examples. When used with a custom Default value: Derived from numberFormat config for number format and from timeFormat config for time format. |
formatType | String |
The format type for labels. One of Default value: - |
labels | Boolean | ExprRef |
A boolean flag indicating if labels should be included as part of the axis. Default value: |
labelAlign | String | ExprRef | ConditionalAxisString |
Horizontal text alignment of axis tick labels, overriding the default setting for the current axis orientation. |
labelAngle | Number | ExprRef |
The rotation angle of the axis labels. Default value: |
labelBaseline | String | ExprRef | ConditionalAxisString |
Vertical text baseline of axis tick labels, overriding the default setting for the current axis orientation. One of |
labelBound | Number | Boolean | ExprRef |
Indicates if labels should be hidden if they exceed the axis range. If Default value: |
labelColor | Null | Color | ExprRef | ConditionalAxisColor |
The color of the tick label, can be in hex color code or regular color name. |
labelExpr | String |
Vega expression for customizing labels. Note: The label text and value can be assessed via the |
labelFlush | Boolean | Number |
Indicates if the first and last axis labels should be aligned flush with the scale range. Flush alignment for a horizontal axis will left-align the first label and right-align the last label. For vertical axes, bottom and top text baselines are applied instead. If this property is a number, it also indicates the number of pixels by which to offset the first and last labels; for example, a value of 2 will flush-align the first and last labels and also push them 2 pixels outward from the center of the axis. The additional adjustment can sometimes help the labels better visually group with corresponding axis ticks. Default value: |
labelFlushOffset | Number | ExprRef |
Indicates the number of pixels by which to offset flush-adjusted labels. For example, a value of Default value: |
labelFont | String | ExprRef | ConditionalAxisString |
The font of the tick label. |
labelFontSize | Number | ExprRef | ConditionalAxisNumber |
The font size of the label, in pixels. |
labelFontStyle | String | ExprRef | ConditionalAxisString |
Font style of the title. |
labelFontWeight | String | Number | ExprRef | ConditionalAxisString |
Font weight of axis tick labels. |
labelLimit | Number | ExprRef |
Maximum allowed pixel width of axis tick labels. Default value: |
labelLineHeight | Number | ExprRef |
Line height in pixels for multi-line label text or label text with |
labelOffset | Number | ExprRef | ConditionalAxisNumber |
Position offset in pixels to apply to labels, in addition to tickOffset. Default value: |
labelOpacity | Number | ExprRef | ConditionalAxisNumber |
The opacity of the labels. |
labelOverlap | String | ExprRef |
The strategy to use for resolving overlap of axis labels. If Default value: |
labelPadding | Number | ExprRef | ConditionalAxisNumber |
The padding in pixels between labels and ticks. Default value: |
labelSeparation | Number | ExprRef |
The minimum separation that must be between label bounding boxes for them to be considered non-overlapping (default |
See also: guide-label
style config (common styles for axis, legend, and header labels).
Example: Using Axis labelExpr
to Display Initial Letters of Month Name
Ticks
Property | Type | Description |
---|---|---|
ticks | Boolean | ExprRef |
Boolean value that determines whether the axis should include ticks. Default value: |
tickBand | String | ExprRef |
For band scales, indicates if ticks and grid lines should be placed at the |
tickCap | String | ExprRef |
The stroke cap for the tick lines’ ending style. One of Default value: |
tickColor | Null | Color | ExprRef | ConditionalAxisColor |
The color of the axis’s tick. Default value: |
tickCount | Number | String | Object | ExprRef |
A desired number of ticks, for axes visualizing quantitative scales. The resulting number may be different so that values are “nice” (multiples of 2, 5, 10) and lie within the underlying scale’s range. For scales of type Default value: Determine using a formula |
tickDash | Number[] | ExprRef | ConditionalAxisNumberArray |
An array of alternating [stroke, space] lengths for dashed tick mark lines. |
tickExtra | Boolean | ExprRef |
Boolean flag indicating if an extra axis tick should be added for the initial position of the axis. This flag is useful for styling axes for |
tickMinStep | Number | ExprRef |
The minimum desired step between axis ticks, in terms of scale domain values. For example, a value of |
tickOffset | Number | ExprRef |
Position offset in pixels to apply to ticks, labels, and gridlines. |
tickOpacity | Number | ExprRef | ConditionalAxisNumber |
Opacity of the ticks. |
tickRound | Boolean | ExprRef |
Boolean flag indicating if pixel position values should be rounded to the nearest integer. Default value: |
tickSize | Number | ExprRef | ConditionalAxisNumber |
The size in pixels of axis ticks. Default value: |
tickWidth | Number | ExprRef | ConditionalAxisNumber |
The width, in pixels, of ticks. Default value: |
values | Number[] | String[] | Boolean[] | DateTime[] | ExprRef |
Explicitly set the visible axis tick values. |
Example: Using Axis tickBand
to Show Grid Between Marks
Using tickBand
, we can change the axis ticks and gridlines to be drawn between marks.
Title
Property | Type | Description |
---|---|---|
title | Text | Null |
A title for the field. If Default value: derived from the field’s name and transformation function ( Notes: 1) You can customize the default field title format by providing the 2) If both field definition’s |
titleAlign | String | ExprRef |
Horizontal text alignment of axis titles. |
titleAnchor | Null | String | ExprRef |
Text anchor position for placing axis titles. |
titleAngle | Number | ExprRef |
Angle in degrees of axis titles. |
titleBaseline | String | ExprRef |
Vertical text baseline for axis titles. One of |
titleColor | Null | Color | ExprRef |
Color of the title, can be in hex color code or regular color name. |
titleFont | String | ExprRef |
Font of the title. (e.g., |
titleFontSize | Number | ExprRef |
Font size of the title. |
titleFontStyle | String | ExprRef |
Font style of the title. |
titleFontWeight | String | Number | ExprRef |
Font weight of the title. This can be either a string (e.g |
titleLimit | Number | ExprRef |
Maximum allowed pixel width of axis titles. |
titleLineHeight | Number | ExprRef |
Line height in pixels for multi-line title text or title text with |
titleOpacity | Number | ExprRef |
Opacity of the axis title. |
titlePadding | Number | ExprRef |
The padding, in pixels, between title and axis. |
titleX | Number | ExprRef |
X-coordinate of the axis title relative to the axis group. |
titleY | Number | ExprRef |
Y-coordinate of the axis title relative to the axis group. |
Example: Customize Title
For example, the following plot has a customized x-axis title.
See also: Axis Title Config and guide-title
style config (common styles for axis, legend, and header titles).
Grid
Property | Type | Description |
---|---|---|
grid | Boolean |
A boolean flag indicating if grid lines should be included as part of the axis Default value: |
gridCap | String | ExprRef |
The stroke cap for grid lines’ ending style. One of Default value: |
gridColor | Null | Color | ExprRef | ConditionalAxisColor |
Color of gridlines. Default value: |
gridDash | Number[] | ExprRef | ConditionalAxisNumberArray |
An array of alternating [stroke, space] lengths for dashed grid lines. |
gridOpacity | Number | ExprRef | ConditionalAxisNumber |
The stroke opacity of grid (value between [0,1]) Default value: |
gridWidth | Number | ExprRef | ConditionalAxisNumber |
The grid width, in pixels. Default value: |
Conditional Axis Properties
We can set axis properties (which can be of type “ConditionalAxisProperty”) to a conditional value definition.
Note that each axis tick, grid line, and label instance is backed by a data object with the following fields, which may be accessed as part of the test condition in a condition axis property.
label
- the string labelvalue
- the data valueindex
- fractional tick index (0
for the first tick and1
for the last tick)
Example: Conditional Axis Properties and Multi-Line Axis Label
In the following example, we adjust the gridDash
and tickDash
properties in a line chart based on whether a particular grid line falls on a year boundary. We also use the labelExpr
property to show multi-line labels for year and month, showing the year number only for January of each year.
We can also conditionally hide some labels and ticks in the following Lasagna plot using conditional labelColor
and tickColor
:
Axis Config
// Top-level View Specification
{
...
"config": {
"axis": : ...,
"axisX": : ...,
"axisY": : ...,
"axisLeft": : ...,
"axisRight": : ...,
"axisTop": : ...,
"axisBottom": : ...,
"axisBand": : ...,
"axisQuantitative": : ...,
"axisTemporal": : ...,
...
}
}
Axis configuration defines default settings for axes. Properties defined under the "axis"
property in the top-level config
object are applied to all axes.
Additional property blocks can target more specific axis types based on the orientation ("axisX"
, "axisY"
, "axisLeft"
, "axisTop"
, etc.), band scale type ("axisBand"
), scale’s data type ("axisDiscrete"
, "axisQuantitative"
, and "axisTemporal"
), or both orientation and scale/data type (e.g., "axisXTemporal"
). For example, properties defined under the "axisBand"
property will only apply to axes visualizing "band"
scales.
An axis configuration supports all axis properties except position
, orient
, format
, values
, and zindex
. In addition, it also supports the disable
property:
Property | Type | Description |
---|---|---|
disable | Boolean |
Disable axis by default. |
Note:
-
If multiple axis config blocks apply to a single axis, type-based options take precedence over orientation-based options, which in turn take precedence over general options.
-
If an axis config has a style property, the style will have lower precedence than any of the axis config properties.
-
In summary, here is the precedence level order for each axis property (from the highest to the lowest):
- Axis properties (
axis.*
) - Axis style (
config.axis[axis.style].*
) - Orientation and type based axis config (e.g.,
config.axisXBand.*
) - Type-based axis config (e.g.,
config.axisBand.*
) - Orientation-based axis config (
config.axisX/Y.*
) - General axis config (
config.axis.*
) - Style of orientation and type based axis config (e.g.,
config.style[config.axisXBand.style].*
) - Style of type-based axis config (e.g.,
config.style[config.axisBand.style].*
) - Style of orientation-based axis config (e.g.,
config.style[config.axisX.style].*
) - Style general axis config (
config.style[config.axis.style].*
)
- Axis properties (
See also: Axis Labels Properties and guide-label
style config (common styles for by axis, legend, and header labels).