Skip to content
SVG Accessibility

SVG Accessibility

Use this when: You need to write real SVG accessibility markup alongside a rendered chart.

SVG Accessibility

Usage

from dataviz import Plot, render_svg
from dataviz.rendering import write_accessible_svg


def main() raises:
    var regions: List[String] = ["North", "South", "East", "West"]
    var revenue: List[Float64] = [420.0, 310.0, 275.0, 390.0]

    var plot = (
        Plot()
        .mark_bar()
        .encode_categorical(x=regions, y=revenue)
        .labels(title="Regional Revenue")
    )

    var svg = render_svg(plot)
    # `svg^` because titling the canvas is a mutation and an SvgCanvas
    # moves rather than copies, so this call consumes it.
    write_accessible_svg(
        svg^,
        "docs/src/examples/out_svg_accessibility.svg",
        "Regional Revenue comparison chart",
        (
            "A chart comparing revenue across four regions: North ($420), South"
            " ($310), East ($275), and West ($390)."
        ),
    )

Related

Related recipes: Minimal Theme

Relevant API: Theme · Colors