[Makie] Displaying LaTeX fraction in xticks

I’m having trouble dealing with xticks.

using CairoMakie
using LaTeXStrings

fig = Figure()

ax = Axis(fig[1,1], xticks = (-pi:pi/2:pi, [L"-\pi", L"-\pi/2", L"0", L"\pi/2", L"\pi"]))

xlims!(ax, -pi, pi)

fig

This code works fine as shown below.

However, the following code generates an error.

using CairoMakie
using LaTeXStrings

fig = Figure()

ax = Axis(fig[1,1], xticks = (-pi:pi/2:pi, [L"-\pi", L"-\frac{\pi}{2}", L"0", L"\frac{\pi}{2}", L"\pi"]))

xlims!(ax, -pi, pi)

fig
{
	"name": "BoundsError",
	"message": "BoundsError: attempt to access 3-element Vector{Point{2, Float64}} at index [4]",
	"stack": "BoundsError: attempt to access 3-element Vector{Point{2, Float64}} at index [4]

Stacktrace:
  [1] getindex
    @ .\\essentials.jl:13 [inlined]
  [2] attr_broadcast_getindex
    @ C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\utilities\\utilities.jl:174 [inlined]
  [3] #2305
    @ C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\basic_recipes\\text.jl:79 [inlined]
  [4] #4
    @ .\\generator.jl:36 [inlined]
  [5] iterate
    @ .\\generator.jl:47 [inlined]
  [6] collect_to!
    @ .\\array.jl:892 [inlined]
  [7] collect_to_with_first!
    @ .\\array.jl:870 [inlined]
  [8] collect(itr::Base.Generator{Base.Iterators.Zip{Tuple{Vector{Point{2, Float32}}, Vector{Int64}}}, Base.var\"#4#5\"{Makie.var\"#2305#2309\"{Vector{Point{2, Float64}}}}})
    @ Base .\\array.jl:844
  [9] map(::Function, ::Vector{Point{2, Float32}}, ::Vector{Int64})
    @ Base .\\abstractarray.jl:3409
 [10] (::Makie.var\"#2304#2308\"{MakieCore.Text{Tuple{Vector{Point{3, Float64}}}}, Observable{Vector{Point{2, Float32}}}, Base.RefValue{Vector{Int64}}})(segs::Vector{Point{2, Float32}}, pos::Vector{Point{3, Float64}}, ::StaticArraysCore.SMatrix{4, 4, Float32, 16}, ::GeometryBasics.HyperRectangle{2, Int64}, ::Nothing, transf::Function, space::Symbol)
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\basic_recipes\\text.jl:78
 [11] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\\essentials.jl:892
 [12] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\\essentials.jl:889
 [13] (::Observables.OnAny)(value::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:420
 [14] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [15] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [16] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [17] setindex!(observable::Observable, val::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:123
 [18] (::Makie.var\"#2303#2306\"{Base.RefValue{Vector{Int64}}, Observable{Vector{ColorTypes.RGBA{Float32}}}, Observable{Vector{Float32}}, Observable{Vector{Point{2, Float32}}}, Observable{Vector{Makie.GlyphCollection}}})(str::Vector{Any}, ts::Float64, f::Symbol, fs::Attributes, al::Tuple{Symbol, Symbol}, rot::Float64, jus::MakieCore.Automatic, lh::Float64, col::ColorTypes.RGBA{Float32}, scol::Tuple{Symbol, Float64}, swi::Int64, www::Int64, offs::Tuple{Float64, Float64})
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\basic_recipes\\text.jl:68
 [19] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\\essentials.jl:892
 [20] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\\essentials.jl:889
 [21] (::Observables.OnAny)(value::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:420
 [22] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [23] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [24] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [25] setindex!(observable::Observable, val::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:123
 [26] (::Observables.SetindexCallback)(x::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:148
 [27] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [28] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [29] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [30] (::Makie.var\"#2311#2312\"{Observable{Vector{Point{3, Float64}}}, Observable{Vector{Any}}})(str_pos::Vector{Tuple{Any, Point{2, Float32}}})
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\basic_recipes\\text.jl:188
 [31] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [32] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [33] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [34] #62
    @ .\\tuple.jl:627 [inlined]
 [35] BottomRF
    @ .\\reduce.jl:86 [inlined]
 [36] afoldl
    @ .\\operators.jl:544 [inlined]
 [37] _foldl_impl
    @ .\\reduce.jl:68 [inlined]
 [38] foldl_impl
    @ .\\reduce.jl:48 [inlined]
 [39] mapfoldl_impl
    @ .\\reduce.jl:44 [inlined]
 [40] mapfoldl
    @ .\\reduce.jl:175 [inlined]
 [41] foldl
    @ .\\reduce.jl:198 [inlined]
 [42] foreach
    @ .\\tuple.jl:627 [inlined]
 [43] (::Makie.var\"#281#282\"{UnionAll, Tuple{Observable{Vector{Tuple{Any, Point{2, Float32}}}}}})(kw::@NamedTuple{}, args::Vector{Tuple{Any, Point{2, Float32}}})
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\interfaces.jl:185
 [44] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\\essentials.jl:892
 [45] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\\essentials.jl:889
 [46] (::Observables.OnAny)(value::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:420
 [47] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [48] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [49] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [50] update_ticklabel_node(closure_args::Tuple{Observable{Bool}, Observable{Any}, Observable{Float32}, Observable{Any}, Observable{Vector{Float64}}}, ticklabel_annotation_obs::Observable{Vector{Tuple{Any, Point{2, Float32}}}}, labelgap::Float32, flipped::Bool, tickpositions::Vector{Point{2, Float32}}, tickstrings::Vector{Any})
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\makielayout\\lineaxis.jl:165
 [51] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\\essentials.jl:892
 [52] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\\essentials.jl:889
 [53] (::Observables.OnAny)(value::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:420
 [54] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [55] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [56] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [57] setindex!(observable::Observable, val::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:123
 [58] update_tickpos_string(closure_args::Tuple{Observable{Vector{Any}}, Observable{Vector{Point{2, Float32}}}, Observable{Vector{Float64}}, Observable{Tuple{Float32, Tuple{Float32, Float32}, Bool}}, Observable{Tuple{Float64, Float64}}}, tickvalues_labels_unfiltered::Tuple{Vector{Float64}, Vector{Any}}, reversed::Bool, scale::typeof(identity))
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\makielayout\\lineaxis.jl:229
 [59] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\\essentials.jl:892
 [60] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\\essentials.jl:889
 [61] (::Observables.OnAny)(value::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:420
 [62] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [63] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [64] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [65] setindex!(observable::Observable, val::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:123
 [66] (::Observables.MapCallback)(value::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:436
--- the last 5 lines are repeated 1 more time ---
 [72] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [73] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [74] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [75] setindex!(observable::Observable, val::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:123
 [76] (::Observables.SetindexCallback)(x::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:148
 [77] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [78] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [79] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [80] setindex!(observable::Observable, val::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:123
 [81] (::Observables.MapCallback)(value::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:436
 [82] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [83] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [84] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [85] setindex!(observable::Observable, val::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:123
 [86] adjustlimits!(la::Axis)
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\makielayout\\blocks\\axis.jl:1005
 [87] (::Makie.var\"#1660#1691\"{Axis})(pxa::GeometryBasics.HyperRectangle{2, Int64}, lims::GeometryBasics.HyperRectangle{2, Float64})
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\makielayout\\blocks\\axis.jl:520
 [88] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\\essentials.jl:892
 [89] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\\essentials.jl:889
 [90] (::Observables.OnAny)(value::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:420
 [91] #invokelatest#2
    @ .\\essentials.jl:892 [inlined]
 [92] invokelatest
    @ .\\essentials.jl:889 [inlined]
 [93] notify
    @ C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:206 [inlined]
 [94] setindex!(observable::Observable, val::Any)
    @ Observables C:\\Users\\lcano\\.julia\\packages\\Observables\\YdEbO\\src\\Observables.jl:123
 [95] reset_limits!(ax::Axis; xauto::Bool, yauto::Bool, zauto::Bool)
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\makielayout\\blocks\\axis.jl:653
 [96] reset_limits!
    @ C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\makielayout\\blocks\\axis.jl:570 [inlined]
 [97] xlims!(ax::Axis, xlims::Tuple{Float64, Irrational{:π}})
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\makielayout\\blocks\\axis.jl:1273
 [98] xlims!(ax::Axis, low::Float64, high::Irrational{:π})
    @ Makie C:\\Users\\lcano\\.julia\\packages\\Makie\\eziUH\\src\\makielayout\\blocks\\axis.jl:1306"
}

I really don’t know what’s going on.

The version of Makie is as follows.

(@v1.10) pkg> st Makie CairoMakie
Status `C:\Users\lcano\.julia\environments\v1.10\Project.toml`
  [13f3f980] CairoMakie v0.12.0
  [ee78f7c6] Makie v0.21.0

Thanks in advance.

It appears that this is a Makie bug, specifically you are having problems with the line

and not the xticks as you might think. Using the following code

begin
    fig = Figure()

    ax = Axis(fig[1, 1], xticks=([-pi, -pi / 2, 0, pi / 2, pi], [L"-\pi", L"-\frac{\pi}{2}", L"0", L"\frac{\pi}{2}", L"\pi"]), limits=((-pi, pi), nothing))

    fig
end

gets your desired behavior right, but it seems that xlims! is not doing the right thing in this case.

1 Like

It works well. I appreciate your quick response.