MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.42k stars 313 forks source link

LaTeXStrings fractions as axis label yields AssertionError: length(positions) == length(colors) #3208

Open jewh opened 1 year ago

jewh commented 1 year ago

Running latest version of CairoMakie - v0.5.10

As in title. MWE to reproduce the error:

using CairoMakie, LaTeXStrings

M = rand(10, 10)

fig = Figure()

ax = Axis(fig[1, 1])

heatmap!(ax, M)

ax.xlabel = L"\frac{\pi}{x}"

fig

Error message:

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 C:\Users\mert4417\.julia\packages\CairoMakie\tsPbW\src\primitives.jl:131
  [2] draw_atomic(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::Union{Lines, LineSegments})
    @ CairoMakie C:\Users\mert4417\.julia\packages\CairoMakie\tsPbW\src\primitives.jl:58
  [3] draw_plot(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::LineSegments{Tuple{Vector{Point{2, Float32}}}})
    @ CairoMakie C:\Users\mert4417\.julia\packages\CairoMakie\tsPbW\src\infrastructure.jl:106
  [4] draw_plot(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::MakieCore.Text{Tuple{Vector{Point{2, Float32}}}})
    @ CairoMakie C:\Users\mert4417\.julia\packages\CairoMakie\tsPbW\src\infrastructure.jl:111
  [5] cairo_draw(screen::CairoMakie.Screen{CairoMakie.IMAGE}, scene::Scene)
    @ CairoMakie C:\Users\mert4417\.julia\packages\CairoMakie\tsPbW\src\infrastructure.jl:47
  [6] backend_show(screen::CairoMakie.Screen{CairoMakie.IMAGE}, io::Base64.Base64EncodePipe, #unused#::MIME{Symbol("image/png")}, scene::Scene)
    @ CairoMakie C:\Users\mert4417\.julia\packages\CairoMakie\tsPbW\src\display.jl:97
  [7] show(io::Base64.Base64EncodePipe, m::MIME{Symbol("image/png")}, figlike::Figure)
    @ Makie C:\Users\mert4417\.julia\packages\Makie\iY5BJ\src\display.jl:177
  [8] base64encode(::Function, ::MIME{Symbol("image/png")}, ::Vararg{Any}; context::Nothing)
    @ Base64 C:\Users\mert4417\AppData\Local\Programs\Julia-1.8.2\share\julia\stdlib\v1.8\Base64\src\encode.jl:209
  [9] _binstringmime
    @ C:\Users\mert4417\AppData\Local\Programs\Julia-1.8.2\share\julia\stdlib\v1.8\Base64\src\Base64.jl:46 [inlined]        
 [10] #stringmime#8
    @ C:\Users\mert4417\AppData\Local\Programs\Julia-1.8.2\share\julia\stdlib\v1.8\Base64\src\Base64.jl:43 [inlined]        
 [11] stringmime
    @ C:\Users\mert4417\AppData\Local\Programs\Julia-1.8.2\share\julia\stdlib\v1.8\Base64\src\Base64.jl:43 [inlined]        
 [12] display(d::VSCodeServer.InlineDisplay, m::MIME{Symbol("image/png")}, x::Figure)
    @ VSCodeServer c:\Users\mert4417\.vscode\extensions\julialang.language-julia-1.51.2\scripts\packages\VSCodeServer\src\display.jl:62
 [13] display(d::VSCodeServer.InlineDisplay, mime::String, x::Any)
    @ Base.Multimedia .\multimedia.jl:216
 [14] display(d::VSCodeServer.InlineDisplay, x::Figure)
    @ VSCodeServer c:\Users\mert4417\.vscode\extensions\julialang.language-julia-1.51.2\scripts\packages\VSCodeServer\src\display.jl:198
 [15] display(x::Any)
    @ Base.Multimedia .\multimedia.jl:328
 [16] display(figlike::Figure; backend::Module, screen_config::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Makie C:\Users\mert4417\.julia\packages\Makie\iY5BJ\src\display.jl:120
 [17] display(figlike::Figure)
    @ Makie C:\Users\mert4417\.julia\packages\Makie\iY5BJ\src\display.jl:109
 [18] #invokelatest#2
    @ .\essentials.jl:729 [inlined]
 [19] invokelatest
    @ .\essentials.jl:726 [inlined]
 [20] (::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\mert4417\.vscode\extensions\julialang.language-julia-1.51.2\scripts\packages\VSCodeServer\src\eval.jl:227
 [21] withpath(f::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer c:\Users\mert4417\.vscode\extensions\julialang.language-julia-1.51.2\scripts\packages\VSCodeServer\src\repl.jl:274
 [22] (::VSCodeServer.var"#66#71"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\mert4417\.vscode\extensions\julialang.language-julia-1.51.2\scripts\packages\VSCodeServer\src\eval.jl:179
 [23] hideprompt(f::VSCodeServer.var"#66#71"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer c:\Users\mert4417\.vscode\extensions\julialang.language-julia-1.51.2\scripts\packages\VSCodeServer\src\repl.jl:38
 [24] (::VSCodeServer.var"#65#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\mert4417\.vscode\extensions\julialang.language-julia-1.51.2\scripts\packages\VSCodeServer\src\eval.jl:150
 [25] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging .\logging.jl:511
 [26] with_logger
    @ .\logging.jl:623 [inlined]
 [27] (::VSCodeServer.var"#64#69"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer c:\Users\mert4417\.vscode\extensions\julialang.language-julia-1.51.2\scripts\packages\VSCodeServer\src\eval.jl:253
 [28] #invokelatest#2
    @ .\essentials.jl:729 [inlined]
 [29] invokelatest(::Any)
    @ Base .\essentials.jl:726
 [30] macro expansion
    @ c:\Users\mert4417\.vscode\extensions\julialang.language-julia-1.51.2\scripts\packages\VSCodeServer\src\eval.jl:34 [inlined]
 [31] (::VSCodeServer.var"#62#63")()
    @ VSCodeServer .\task.jl:484

Seems to be specific to fractions. If one replaces the sixth line with `ax.xlabel=L"\pi x" everything behaves as expected.

jewh commented 1 year ago

System info:

julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf26 (2022-09-29 15:21 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, tigerlake)
  Threads: 16 on 16 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 16
Kolaru commented 1 year ago

The problem is the line, it fails with \sqrt as well.

Something goes wrong when the label is changed. If the xlabel is set at the axis creation, it works, e.g.

using CairoMakie

fig = Figure()
ax = Axis(fig[1, 1] ; xlabel = L"\frac{\pi}{x}")
fig
jkrumbiegel commented 1 year ago

Yes this seems to be a regression, the rotation of those lines also broke, there's another issue about that open already. Haven't had time to track it down, yet.

jkrumbiegel commented 9 months ago

I actually think this has to do with these lines https://github.com/MakieOrg/Makie.jl/blob/e4f363b1d081bc799a8a998ba7b4aad909a8c791/src/interfaces.jl#L85-L86 from this PR https://github.com/MakieOrg/Makie.jl/pull/3062 cc @SimonDanisch