1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
.. currentmodule:: altair
.. _user-guide-configuration:
Top-Level Chart Configuration
=============================
Many aspects of a chart's appearance can be configured at the top level using
the ``configure_*()`` methods.
These methods and the properties that they set are only valid at the top level
of a chart, and can be thought of as a way of setting a chart theme: that is,
they set the default styles for the entire chart, and these defaults can be
overridden by specific style settings associated with chart elements.
These methods and their arguments will be outlined below:
- :ref:`config-chart` :meth:`Chart.configure`
- :ref:`config-axis` :meth:`Chart.configure_axis`
- :ref:`config-header` :meth:`Chart.configure_header`
- :ref:`config-legend` :meth:`Chart.configure_legend`
- :ref:`config-mark` :meth:`Chart.configure_mark`
- :ref:`config-scale` :meth:`Chart.configure_scale`
- :ref:`config-range` :meth:`Chart.configure_range`
- :ref:`config-projection` :meth:`Chart.configure_projection`
- :ref:`config-composition` :meth:`Chart.configure_concat`, :meth:`Chart.configure_facet`
- :ref:`config-selection` :meth:`Chart.configure_selection`
- :ref:`config-title` :meth:`Chart.configure_title`
- :ref:`config-view` :meth:`Chart.configure_view`
For more discussion of approaches to chart customization, see
:ref:`user-guide-customization`.
.. _config-chart:
Chart Configuration
-------------------
The :meth:`Chart.configure` method adds a :class:`Config` instance to the chart,
and accepts the following parameters:
.. altair-object-table:: altair.Config
.. _config-axis:
Axis Configuration
------------------
Axis configuration defines default settings for axes and can be set using
the :meth:`Chart.configure_axis` method.
Properties defined here are applied to all axes in the figure.
Additional property blocks can target more specific axis types based on the
orientation ("axisX", "axisY", "axisLeft", "axisTop", etc.) or band scale
type ("axisBand").
For example, properties defined under the "axisBand"
property will only apply to axes visualizing "band" scales.
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.
The methods are the following:
- :meth:`Chart.configure_axis`
- :meth:`Chart.configure_axisBand`
- :meth:`Chart.configure_axisBottom`
- :meth:`Chart.configure_axisLeft`
- :meth:`Chart.configure_axisRight`
- :meth:`Chart.configure_axisTop`
- :meth:`Chart.configure_axisX`
- :meth:`Chart.configure_axisY`
- :meth:`Chart.configure_axisDiscrete`
- :meth:`Chart.configure_axisPoint`
- :meth:`Chart.configure_axisQuantitative`
- :meth:`Chart.configure_axisTemporal`
- :meth:`Chart.configure_axisXBand`
- :meth:`Chart.configure_axisXDiscrete`
- :meth:`Chart.configure_axisXPoint`
- :meth:`Chart.configure_axisXQuantitative`
- :meth:`Chart.configure_axisXTemporal`
- :meth:`Chart.configure_axisYBand`
- :meth:`Chart.configure_axisYDiscrete`
- :meth:`Chart.configure_axisYPoint`
- :meth:`Chart.configure_axisYQuantitative`
- :meth:`Chart.configure_axisYTemporal`
They have the following properties:
.. altair-object-table:: altair.AxisConfig
.. _config-header:
Header Configuration
--------------------
Header configuration defines default settings for headers including the font, color,
size, and position of the title and labels and can be set using
the :meth:`Chart.configure_header` method. Here is an example:
.. altair-plot::
import altair as alt
from vega_datasets import data
source = data.cars.url
chart = alt.Chart(source).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color='Origin:N',
column='Origin:N'
).properties(
width=180,
height=180
)
chart.configure_header(
titleColor='green',
titleFontSize=14,
labelColor='red',
labelFontSize=14
)
Additional property blocks can target more specific header types. The methods are the following:
- :meth:`Chart.configure_header`
- :meth:`Chart.configure_headerColumn`
- :meth:`Chart.configure_headerFacet`
- :meth:`Chart.configure_headerRow`
They have the following properties:
.. altair-object-table:: altair.HeaderConfig
.. _config-legend:
Legend Configuration
--------------------
The :meth:`Chart.configure_legend` allows you to customize the appearance of chart
legends, including location, fonts, bounding boxes, colors, and more.
Here is an example:
.. altair-plot::
import altair as alt
from vega_datasets import data
source = data.cars.url
chart = alt.Chart(source).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color='Origin:N'
)
chart.configure_legend(
strokeColor='gray',
fillColor='#EEEEEE',
padding=10,
cornerRadius=10,
orient='top-right'
)
Additional properties are summarized in the following table:
.. altair-object-table:: altair.LegendConfig
.. _config-mark:
Mark and Mark Style Configuration
---------------------------------
The mark configuration can be set using the :meth:`Chart.configure_mark`
method, which sets the default properties for all marks in the chart.
In addition, the config object also provides mark-specific configuration
using the mark type (e.g. :meth:`Chart.configure_area`) for
defining default properties for each mark.
For general configuration of all mark types, use:
- :meth:`Chart.configure_mark`
For configurations specific to particular mark types, use:
- :meth:`Chart.configure_arc`
- :meth:`Chart.configure_area`
- :meth:`Chart.configure_bar`
- :meth:`Chart.configure_boxplot`
- :meth:`Chart.configure_circle`
- :meth:`Chart.configure_errorband`
- :meth:`Chart.configure_errorbar`
- :meth:`Chart.configure_geoshape`
- :meth:`Chart.configure_image`
- :meth:`Chart.configure_line`
- :meth:`Chart.configure_point`
- :meth:`Chart.configure_rect`
- :meth:`Chart.configure_rule`
- :meth:`Chart.configure_square`
- :meth:`Chart.configure_text`
- :meth:`Chart.configure_tick`
- :meth:`Chart.configure_trail`
Each of the above methods accepts the following properties:
.. altair-object-table:: altair.MarkConfig
In addition to the default mark properties above, default values can be
further customized using named styles defined as keyword arguments to
the :meth:`Chart.configure_style` method.
Styles can then be invoked by including a style property within a mark
definition object.
.. _config-scale:
Scale Configuration
-------------------
Scales can be configured using :meth:`Chart.configure_scale`, which has
the following properties:
.. altair-object-table:: altair.ScaleConfig
.. _config-range:
Scale Range Configuration
-------------------------
Scale ranges can be configured using :meth:`Chart.configure_range`, which has
the following properties:
.. altair-object-table:: altair.RangeConfig
.. _config-projection:
Projection Configuration
------------------------
Projections can be configured using :meth:`Chart.configure_projection`,
which has the following properties:
.. altair-object-table:: altair.ProjectionConfig
.. _config-composition:
Concat and Facet Configuration
------------------------------
Various aspects of concat and facet charts can be configured using :meth:`Chart.configure_concat`
and :meth:`Chart.configure_facet`, which have the following properties:
.. altair-object-table:: altair.CompositionConfig
.. _config-selection:
Selection Configuration
-----------------------
Selections can be configured using :meth:`Chart.configure_selection`,
which has the following properties:
.. altair-object-table:: altair.SelectionConfig
.. _config-title:
Title Configuration
-------------------
The :meth:`Chart.configure_title` method allows configuration of the chart
title, including the font, color, placement, and orientation.
Here is an example:
.. altair-plot::
import altair as alt
from vega_datasets import data
source = data.cars.url
chart = alt.Chart(source).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
).properties(
title='Cars Data'
)
chart.configure_title(
fontSize=20,
font='Courier',
anchor='start',
color='gray'
)
Additional title configuration options are listed in the following table:
.. altair-object-table:: altair.TitleConfig
.. _config-view:
View Configuration
------------------
The :meth:`Chart.configure_view` method allows you to configure aspects of the
chart's *view*, i.e. the area of the screen in which the data and scales are
drawn. Here is an example to demonstrate some of the visual features that can
be controlled:
.. altair-plot::
import altair as alt
from vega_datasets import data
source = data.cars.url
chart = alt.Chart(source).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
)
chart.configure_view(
continuousHeight=200,
continuousWidth=200,
strokeWidth=4,
fill='#FFEEDD',
stroke='red',
)
Additional properties are summarized in the following table:
.. altair-object-table:: altair.ViewConfig
|