Skip to content

Version 5.5.0

Latest
Compare
Choose a tag to compare
@jonmmease jonmmease released this 24 Nov 00:12
· 3 commits to main since this release
b2ff8ce

Release 5.5.0

The Vega-Altair team is pleased to announce the release of version 5.5.0. This version introduces several exciting new features and enhancements including a revamped theme system, a new renderer optimized for screen readers, and numerous type system updates that improve auto-completion and make it easier to integrate Altair into larger typed programs.

This release adds Python 3.13 and removes Python 3.8 support. It also includes a variety of documentation improvements and a range of important bug fixes.

Thanks to our maintainers (@binste, @dangotbanned, @joelostblom, @mattijn, and @jonmmease), returning contributors (@MarcoGorelli, @daylinmorgan, and @dsmedia), and first time contributors (@jpn--, @davidgroves, and @apoorvkh) for these improvements.

What's Changed

Deprecation

alt.themes

This release deprecates the alt.themes ThemeRegistry object and replaces it with an improved theme API in the new alt.theme module.
See the updated Chart Themes documentation for more information.

Note

Usage of the legacy alt.themes registry will be supported until version 6, but will now display a warning on first use.

Example of registering a custom theme

import altair as alt
import pandas as pd

data = pd.DataFrame({'x': [5, 3, 6, 7, 2],
                     'y': ['A', 'B', 'C', 'D', 'E']})

@alt.theme.register("my_little_theme", enable=True)
def custom_theme():
    return alt.theme.ThemeConfig(
        config={
            "bar":{"color":"black"}
        }
    )

chart = alt.Chart(data).mark_bar().encode(
    x='x',
    y='y',
)
chart  # enable default using `alt.theme.enable("default")`

Example of instant feedback while you define a theme config through Pylance in VSCode

Enhancements

Olli Renderer

This release integrates the Olli project to provide a chart renderer that augments chart visualizations with a keyboard-navigable structure accessible to screen readers.

  • Add 'olli' renderer to generate accessible text structures for screen reader users by @binste in #3580

Example of olli renderer:

import altair as alt
from vega_datasets import data

alt.renderers.enable("olli")

cars = data.cars.url
chart = alt.Chart(cars).mark_bar().encode(
    y='Cylinders:O',
    x='mean_acc:Q'
).transform_aggregate(
    mean_acc='mean(Acceleration)',
    groupby=["Cylinders"]
)
chart

Expressions and Selections

Several improvements were made to Altair's expression and selection APIs:

Example of combining predicates within .transform_filter

import altair as alt
from vega_datasets import data

source = data.population.url
chart = alt.Chart(source).mark_line().encode(
    x="age:O",
    y="sum(people):Q",
    color="year:O"
).transform_filter(
    ~alt.FieldRangePredicate(field='year', range=[1900, 1960]) 
    & (alt.datum.age <= 70)
)
chart

Example of using Python datetime.date for value in alt.selection_interval()

import datetime
import altair as alt
from vega_datasets import data

source = data.unemployment_across_industries.url
dt_values = [datetime.date(2005, 1, 1), datetime.date(2009, 1, 1)]

brush = alt.selection_interval(
    encodings=['x'],
    value={"x": dt_values}
)

base = alt.Chart(source).mark_area(
    color='goldenrod',
    opacity=0.3
).encode(
    x='yearmonth(date):T',
    y='sum(count):Q',
)

background = base.add_params(brush)
selected = base.transform_filter(brush).mark_area(color='goldenrod')

background + selected

Multiple predicates and constraints in Chart.transform_filter

Example of using keyword-argument constraints to simplify filter compositions:

import altair as alt
from vega_datasets import data

source = data.population.url
chart = alt.Chart(source).mark_area().encode(
    x="age:O",
    y="sum(people):Q",
    color="year:O"
).transform_filter(year=2000, sex=1)
chart
image

Bug Fixes

Documentation

Several new examples were added to the documentation

Example of using alt.when().then().otherwise()

import altair as alt
from vega_datasets import data

source = data.cars()

brush = alt.selection_interval()

chart = alt.Chart(source).mark_point().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color=alt.when(brush).then("Origin").otherwise(alt.value("lightgray"))
).add_params(
    brush
)
chart

Example of using luminance in an expression to dynamically colorize text

import altair as alt
from vega_datasets import data

source = data.barley()

base = alt.Chart(source).encode(
    x=alt.X('sum(yield):Q').stack('zero'),
    y=alt.Y('site:O').sort('-x'),
    text=alt.Text('sum(yield):Q', format='.0f')
)

bars = base.mark_bar(
    tooltip=alt.expr("luminance(scale('color', datum.sum_yield))")
).encode(
    color='sum(yield):Q'
)

text = base.mark_text(
    align='right',
    dx=-3,
    color=alt.expr("luminance(scale('color', datum.sum_yield)) > 0.5 ? 'black' : 'white'")
)

bars + text

Maintenance

Full Changelog: v5.4.1...v5.5.0