Skip to content

Example gallery

A collection of plots generated with sglduck, organized by dataset. The examples use an in-memory DuckDB database loaded with the bundled datasets, and the same render helper as the Get started guide.

import duckdb
import sglduck

con = duckdb.connect()
con.register("cars", sglduck.data.cars())
con.register("trees", sglduck.data.trees())


def render(sgl):
    print(sglduck.db_get_plot(con, sgl).to_svg())

Cars

render("""
    visualize
        horsepower as x,
        miles_per_gallon as y
    from cars
    using points
""")
40 60 80 100 120 140 160 180 200 220 10 15 20 25 30 35 40 45 miles_per_gallon horsepower
render("""
    visualize
        horsepower as x,
        miles_per_gallon as y
    from cars
    using (
        points
        layer
        regression line
    )
    facet by
        origin
    scale by
        log(x),
        log(y)
""")
40 63 100 158 8 10 13 16 20 25 32 40 Europe 40 63 100 158 Japan 40 63 100 158 USA miles_per_gallon horsepower
render("""
    visualize
        count(*) as theta,
        origin as color
    from cars
    group by
        origin
    using bars
    title
        theta as 'Number of Cars',
        color as 'Country of Origin'
""")
0 50 100 150 200 250 300 350 400 Number of Cars Country of Origin USA Europe Japan
render("""
    visualize
        bin(miles_per_gallon) as x,
        count(*) as y
    from cars
    group by
        bin(miles_per_gallon)
    using bars
""")
10 15 20 25 30 35 40 45 0 5 10 15 20 25 30 35 count(*) bin(miles_per_gallon)
render("""
    visualize
        origin as x,
        miles_per_gallon as y
    from cars
    using boxes
    scale by
        log(y)
""")
USA Europe Japan 8 10 13 16 20 25 32 40 miles_per_gallon origin

Trees

render("""
    visualize
        age as x,
        circumference as y
    from trees
    collect by
        tree_id
    using lines
""")
200 400 600 800 1,000 1,200 1,400 1,600 40 60 80 100 120 140 160 180 200 220 circumference age
render("""
    visualize
        age as theta,
        radius as r
    from (
        select
            *,
            circumference / (2 * pi()) as radius
        from trees
    )
    collect by
        tree_id
    using lines
""")
200 400 600 800 1,000 1,200 1,400 10 20 30 radius age