# GLMakie saving Axis

**URL:** <https://discourse.julialang.org/t/glmakie-saving-axis/122358>\
**Category:** General Usage\
**Created:** [November 6, 2024, 9:37pm UTC](https://discourse.julialang.org/t/glmakie-saving-axis/122358 "2024-11-06T21:37:07Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [November 7, 2024, 9:32pm UTC](https://discourse.julialang.org/t/glmakie-saving-axis/122358/9 "2024-11-07T21:32:18Z")

</div>

GLMakie doesn’t do svg, so you have to use CairoMakie. And `repr` doesn’t have a way to specify a different backend to use. So one has to take a slight detour through `save`:

```julia
using CairoMakie
using GLMakie
GLMakie.activate!()

f = Figure()
for i in 1:3, j in 1:3
    Axis(f[i, j], title = "$i $j")
end
display(f)

function outer_bbox(ax; padding)
    sbb = ax.layoutobservables.suggestedbbox[]
    prot = ax.layoutobservables.protrusions[]
    o = sbb.origin .- (prot.left, prot.bottom) .- padding
    w = sbb.widths .+ (prot.left + prot.right, prot.bottom + prot.top) .+ 2 * padding
    Rect2f(o, w)
end

function save_cropped_svg(file, scene, bbox)
    sw, sh = scene.viewport[].widths
    ox, oy = bbox.origin
    w, h = bbox.widths
    svg = mktempdir() do dir
        save(joinpath(dir, "output.svg"), scene; backend = CairoMakie)
        read(joinpath(dir, "output.svg"), String)
    end
    svg = replace(
        svg,
        r"viewBox=\".*?\"" => "viewBox=\"$ox $(sh - oy - h) $w $h\"",
        r"width=\".*?\"" => "width=\"$w\"",
        r"height=\".*?\"" => "height=\"$h\"",
        count = 3,
    )
    open(file, "w") do io
        write(io, svg)
    end
    return
end

ax = current_axis()

save_cropped_svg("test.svg", ax.blockscene, outer_bbox(ax; padding = 10))

```

---

_[View the full topic](https://discourse.julialang.org/t/glmakie-saving-axis/122358)._
