# Makie LaTeX fraction in y-axis label

**URL:** <https://discourse.julialang.org/t/makie-latex-fraction-in-y-axis-label/102365>\
**Category:** Visualization\
**Tags:** latex, makie\
**Created:** [August 1, 2023, 6:36pm UTC](https://discourse.julialang.org/t/makie-latex-fraction-in-y-axis-label/102365 "2023-08-01T18:36:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxee/32/52904_2.png) [@maxee](https://discourse.julialang.org/u/maxee)\
**Post date:** [August 1, 2023, 6:36pm UTC](https://discourse.julialang.org/t/makie-latex-fraction-in-y-axis-label/102365/1 "2023-08-01T18:36:09Z")

</div>

Is there a way to allow the y-axis label in Makie be a fraction? Here is a minimal working example:

```julia
using CairoMakie

fig = Figure()
ax = Axis(fig[1,1])
lines!(ax, rand(5))
ax.ylabel = L"$\frac{a}{b}$"
save("file.pdf", fig)

```

I get the following error:

```julia
ERROR: AssertionError: length(positions) == length(colors)
Stacktrace:
  [1] draw_multi(primitive::LineSegments{Tuple{Vector{Point{2, Float32}}}}, ctx::Cairo.CairoContext, positions::Vector{Vec{2, Float32}}, colors::Vector{ColorTypes.RGBA{Float32}}, linewidths::Vector{Float32}, dash::Nothing)
    @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/primitives.jl:165
  [2] draw_atomic(scene::Scene, screen::CairoMakie.Screen{CairoMakie.PDF}, primitive::Union{LineSegments, Lines})
    @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/primitives.jl:63
  [3] draw_plot(scene::Scene, screen::CairoMakie.Screen{CairoMakie.PDF}, primitive::LineSegments{Tuple{Vector{Point{2, Float32}}}})
    @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/infrastructure.jl:131
  [4] cairo_draw(screen::CairoMakie.Screen{CairoMakie.PDF}, scene::Scene)
    @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/infrastructure.jl:51
  [5] backend_show(screen::CairoMakie.Screen{CairoMakie.PDF}, io::IOStream, #unused#::MIME{Symbol("application/pdf")}, scene::Scene)
    @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/display.jl:97
  [6] (::Makie.var"#1099#1100"{Module, Bool, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Figure, MIME{Symbol("application/pdf")}, Scene})(io::IOStream)
    @ Makie ~/.julia/packages/Makie/uAmck/src/display.jl:325
  [7] open(::Makie.var"#1099#1100"{Module, Bool, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Figure, MIME{Symbol("application/pdf")}, Scene}, ::String, ::Vararg{String}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./io.jl:395
  [8] open
    @ ./io.jl:392 [inlined]
  [9] save(file::FileIO.File{FileIO.DataFormat{:PDF}, String}, fig::Figure; resolution::Tuple{Int64, Int64}, backend::Module, update::Bool, screen_config::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/uAmck/src/display.jl:319
 [10] save(file::FileIO.File{FileIO.DataFormat{:PDF}, String}, fig::Figure)
    @ Makie ~/.julia/packages/Makie/uAmck/src/display.jl:297
 [11] save(filename::String, fig::Figure; args::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie ~/.julia/packages/Makie/uAmck/src/display.jl:294
 [12] save(filename::String, fig::Figure)
    @ Makie ~/.julia/packages/Makie/uAmck/src/display.jl:291
 [13] top-level scope
    @ REPL[17]:1

```

---

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [August 1, 2023, 6:48pm UTC](https://discourse.julialang.org/t/makie-latex-fraction-in-y-axis-label/102365/2 "2023-08-01T18:48:21Z")

</div>

I think for LaTeX strings you have to set them at axis creation. This should work:

```julia
using CairoMakie
using LaTeXStrings

fig = Figure()
ax = Axis(
    fig[1,1] ;
    ylabel = L"$\frac{a}{b}$" 
)
lines!(ax, rand(5))
save("file.pdf", fig)

```

---

<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:** [August 1, 2023, 7:59pm UTC](https://discourse.julialang.org/t/makie-latex-fraction-in-y-axis-label/102365/3 "2023-08-01T19:59:31Z")

</div>

It should also work the other way around, if not I’d consider that a bug. Please open an issue if you have time 🙂
