# Error message when using AoG/Makie with "yscale=log10", for my particular data

Hello all,
when running the following piece of code, I obtain an error. I have found out that it is due to the fact of using yscale=log10. If I use yscale=log there is no problem. In the x coordinate I have no problem.

# %%
plt = Vector{Layer}(undef, length(ϵ))
g = ["black", "red", "blue", "green", "cyan"]
labels = (e->"ϵ=$e").(ϵ) println(labels) length(plt) # %% for i = 1:length(ϵ) ρ_f = rar[i].mass_spline.derivative(1) r = rar[i].r ρ=ρ_f(r) df_plot = (x=r/rₛ, y=ρ./(4*pi*r.^2), grp=fill(labels[i],length(r))) plt[i]= data(df_plot)*mapping(:x,:y,color=:grp)*visual(Lines, linewidth=4) end draw(sum(plt), axis=(xlabel=L"r [r_{\mathrm{Sch}}]", ylabel=L"$ρ$[$M_⊙$/kpc³]", limits=((1.e-1,nothing),(1., nothing)), xscale=log10, yscale=log10))|> display  The error message is as follows: ERROR: InexactError: trunc(Int64, NaN) Stacktrace: [1] trunc @ ./float.jl:805 [inlined] [2] round @ ./float.jl:369 [inlined] [3] (::Colon)(start::Float32, step::Float32, stop::Float32) @ Base ./twiceprecision.jl:434 [4] get_minor_tickvalues(i::IntervalsBetween, scale::typeof(log10), tickvalues::Vector{Float32}, vmin::Float32, vmax::Float32) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/lineaxis.jl:665 [5] (::Makie.MakieLayout.var"#194#225"{Observable{Vector{Float32}}, Observable{Any}, Attributes})(tickvalues::Vector{Float32}, minorticks::IntervalsBetween) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/lineaxis.jl:238 [6] (::Observables.OnUpdate{Makie.MakieLayout.var"#194#225"{Observable{Vector{Float32}}, Observable{Any}, Attributes}, Tuple{Observable{Vector{Float32}}, Observable{Any}}})(#unused#::Vector{Float32}) @ Observables ~/.julia/packages/Observables/OFj0u/src/Observables.jl:334 [7] #invokelatest#2 @ ./essentials.jl:716 [inlined] [8] invokelatest @ ./essentials.jl:714 [inlined] [9] notify @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:88 [inlined] [10] setindex!(observable::Observable{Vector{Float32}}, val::Vector{Float64}) @ Observables ~/.julia/packages/Observables/OFj0u/src/Observables.jl:248 [11] (::Makie.MakieLayout.var"#190#221"{Observable{Vector{AbstractString}}, Observable{Vector{Point{2, Float32}}}, Observable{Vector{Float32}}, Observable{Tuple{Float32, Tuple{Float32, Float32}, Bool}}, Observable{Any}, Attributes})(tickvalues_labels_unfiltered::Tuple{Vector{Float64}, Vector{String}}, reversed::Bool) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/lineaxis.jl:213 [12] (::Observables.OnUpdate{Makie.MakieLayout.var"#190#221"{Observable{Vector{AbstractString}}, Observable{Vector{Point{2, Float32}}}, Observable{Vector{Float32}}, Observable{Tuple{Float32, Tuple{Float32, Float32}, Bool}}, Observable{Any}, Attributes}, Tuple{Observable{Tuple{Vector{Float64}, Vector{String}}}, Observable{Any}}})(#unused#::Tuple{Vector{Float64}, Vector{String}}) @ Observables ~/.julia/packages/Observables/OFj0u/src/Observables.jl:334 [13] #invokelatest#2 @ ./essentials.jl:716 [inlined] [14] invokelatest @ ./essentials.jl:714 [inlined] [15] notify @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:88 [inlined] [16] setindex!(observable::Observable{Tuple{Vector{Float64}, Vector{String}}}, val::Tuple{Vector{Float64}, Vector{String}}) @ Observables ~/.julia/packages/Observables/OFj0u/src/Observables.jl:248 [17] (::Observables.MapUpdater{Makie.MakieLayout.var"#189#220", Tuple{Vector{Float64}, Vector{String}}})(::Tuple{Float32, Tuple{Float32, Float32}, Bool}, ::Vararg{Any}) @ Observables ~/.julia/packages/Observables/OFj0u/src/Observables.jl:372 [18] (::Observables.OnUpdate{Observables.MapUpdater{Makie.MakieLayout.var"#189#220", Tuple{Vector{Float64}, Vector{String}}}, Tuple{Observable{Tuple{Float32, Tuple{Float32, Float32}, Bool}}, Observable{Any}, Observable{Any}, Observable{Any}, Observable{Any}}})(#unused#::Tuple{Float32, Float32}) @ Observables ~/.julia/packages/Observables/OFj0u/src/Observables.jl:334 [19] #invokelatest#2 @ ./essentials.jl:716 [inlined] [20] invokelatest @ ./essentials.jl:714 [inlined] [21] notify @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:88 [inlined] [22] setindex! @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:248 [inlined] [23] (::Observables.var"#3#4"{Any, Observable{Any}})(value::Tuple{Float32, Float32}) @ Observables ~/.julia/packages/Observables/OFj0u/src/Observables.jl:58 [24] #invokelatest#2 @ ./essentials.jl:716 [inlined] [25] invokelatest @ ./essentials.jl:714 [inlined] [26] notify @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:88 [inlined] [27] setindex! @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:248 [inlined] [28] (::Makie.MakieLayout.var"#268#299"{Observable{Tuple{Float32, Float32}}, Observable{Tuple{Float32, Float32}}})(lims::GeometryBasics.HyperRectangle{2, Float32}) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/layoutables/axis.jl:207 [29] #invokelatest#2 @ ./essentials.jl:716 [inlined] [30] invokelatest @ ./essentials.jl:714 [inlined] [31] notify @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:88 [inlined] [32] setindex! @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:248 [inlined] [33] adjustlimits!(la::Axis) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/layoutables/axis.jl:890 [34] #282 @ ~/.julia/packages/Makie/lgPZh/src/makielayout/layoutables/axis.jl:446 [inlined] [35] (::Observables.OnUpdate{Makie.MakieLayout.var"#282#315"{Axis}, Tuple{Observable{GeometryBasics.HyperRectangle{2, Int64}}, Observable{GeometryBasics.HyperRectangle{2, Float32}}}})(#unused#::GeometryBasics.HyperRectangle{2, Float32}) @ Observables ~/.julia/packages/Observables/OFj0u/src/Observables.jl:334 [36] #invokelatest#2 @ ./essentials.jl:716 [inlined] [37] invokelatest @ ./essentials.jl:714 [inlined] [38] notify @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:88 [inlined] [39] setindex! @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:248 [inlined] [40] reset_limits!(ax::Axis; xauto::Bool, yauto::Bool, zauto::Bool) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/layoutables/axis.jl:546 [41] reset_limits! @ ~/.julia/packages/Makie/lgPZh/src/makielayout/layoutables/axis.jl:471 [inlined] [42] plot!(::Axis, ::Type{Lines}, ::Attributes, ::Vector{Float64}, ::Vararg{Vector{Float64}}; kw_attributes::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/layoutables/axis.jl:699 [43] plot! @ ~/.julia/packages/Makie/lgPZh/src/makielayout/layoutables/axis.jl:688 [inlined] [44] #plot!#340 @ ~/.julia/packages/Makie/lgPZh/src/makielayout/layoutables/axis.jl:705 [inlined] [45] plot!(ae::AxisEntries) @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/aCs1Y/src/entries.jl:75 [46] foreach(f::typeof(plot!), itr::Matrix{AxisEntries}) @ Base ./abstractarray.jl:2694 [47] plot!(fig::Figure, s::AlgebraOfGraphics.Layers; axis::NamedTuple{(:xlabel, :ylabel, :limits, :xscale, :yscale), Tuple{LaTeXStrings.LaTeXString, LaTeXStrings.LaTeXString, Tuple{Tuple{Float64, Nothing}, Tuple{Float64, Nothing}}, typeof(log10), typeof(log10)}}, palettes::NamedTuple{(), Tuple{}}) @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/aCs1Y/src/draw.jl:22 [48] (::AlgebraOfGraphics.var"#237#238"{NamedTuple{(:xlabel, :ylabel, :limits, :xscale, :yscale), Tuple{LaTeXStrings.LaTeXString, LaTeXStrings.LaTeXString, Tuple{Tuple{Float64, Nothing}, Tuple{Float64, Nothing}}, typeof(log10), typeof(log10)}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, AlgebraOfGraphics.Layers})(f::Figure) @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/aCs1Y/src/draw.jl:46 [49] update @ ~/.julia/packages/AlgebraOfGraphics/aCs1Y/src/draw.jl:10 [inlined] [50] #draw#236 @ ~/.julia/packages/AlgebraOfGraphics/aCs1Y/src/draw.jl:45 [inlined]  I would appreciate any help with this. It seems some kind of MWE is needed for us to be able to help. I wasn’t able to reproduce the error with some arbitrary data. Quoted from Please read: make it easier to help you Thanks, good idea. Here is the MWE. I reduced the arrays 2 orders of magnitude and the error still happens. using AlgebraOfGraphics, CairoMakie G = 4.300923924e-6 c = 2.997925e5 # km s^-1 M_bh = 4.075e6 # M_sun rₛ = 2.0*G*M_bh / c^2 r = [2.1399874335584637e-16, 1.848243353972948e-15, 1.840394568298999e-14, 2.736140625305719e-13, 4.067858952859116e-12, 6.047743419075033e-11, 1.2276346282545895e-9, 3.9834683097582335e-9, 1.5479418853988395e-8, 1.144703530490389e-5, 0.03997853658533462, 0.2299709640296559, 0.34014964461128394, 0.4385004351724096, 0.5578990663389737, 0.7114672228460812, 0.9763533594505319, 1.1441434177341583, 1.365990861819754, 1.677090936434432, 2.1278111596720937, 2.482194074928288, 3.0585748277163556, 3.6629031104845784, 4.232518651409611, 5.085177118720062, 6.333668025195292, 7.451278025838863, 8.71773209463394, 10.364043898956899, 12.155450557352246, 14.703191697727153, 19.6429523227885, 26.019464547251594] ρ = [62.68858141177715, 4676.105478962704, 463647.45279899804, 1.0248087227352521e8, 2.265144835945498e10, 5.002159072000619e12, 1.4151751005888295e15, 4.667393019436629e13, 283858.5322671351, 314.4371978961644, 787624.7498009424, 2.559885665449207e7, 5.5881154221265234e7, 9.2702274750115e7, 1.4971039743415692e8, 2.4263111918766952e8, 4.5351182376518166e8, 6.191538695852668e8, 8.745861675682513e8, 1.2983531170562708e9, 2.0334582702784247e9, 2.6963351472150993e9, 3.893154755387953e9, 5.241539631792803e9, 6.531326784553669e9, 8.363005809874252e9, 1.0530668742452e10, 1.17305490765353e10, 1.2173090351170477e10, 1.1494658819116295e10, 9.703525328328575e9, 6.523490406053474e9, 1.8110008280252154e9, 1.650145537603745e7] df = (x=r/rₛ, y=ρ./(4π*r.^2)) plt = data(df)*mapping(:x,:y)*visual(Lines, linewidth=4) draw(plt, axis=(xlabel=L"r [r_{\mathrm{Sch}}]", ylabel=L"$ρ$[$M_⊙$/kpc³]", limits=((1.e-1,nothing),(1., nothing)), xscale=log10, yscale=log10))|> display  If I change yscale=log10 to log, the error goes away. With log2 the error also happens. I hope this MWE can help you to help me Best. Yes, this reproduces your error. I can’t find a real solution for now, but it seems that the first 8 y-values hit some threshold. If you set your y-limit to some value it plots something: draw(plt, axis=(xlabel=L"r [r_{\mathrm{Sch}}]", ylabel=L"$ρ$[$M_⊙\$/kpc³]",
limits=((1.e-1,nothing),(1., 1.e29)),
xscale=log10, yscale=log10))


you are loosing the first 8 values in the graph, but perhaps they don’t hold too much information anyways.
Perhaps I can dive deeper tomorrow or other people know more than I can provide for now.

Thanks @oheil !
For this MWE there are 8 y values, but for the original problem this corresponds to 800 values and I cannot loose them. For this case, the y values reach order 10^33.

Haven’t had a chance to look at it precisely yet, but such a thing smells like a Float32 problem. If you want you can poke around in the get_minor_tickvalues function a bit that produces the error, see what tickvalues, vmin and vmax are and where the NaN is introduced.

Yes, it is exactly this. Currently checking for a tweak…
AFAIK Makie states that it is working with Float32, so this may be not a bug but intended and so out of scope of Makie. But opening an issue (later) doesn’t harm I guess.

Thanks jules, how can I see those values?
The data comes from Python through PyCall, but should be doble precision.

Thanks. If I understand correctly, there is a reason for Makie to work with Float32? Do you have any suggestion to overcome this problem?

Yes, I have found a code change, which produces the plot of your MWE and No, I can’t remember the reason for this, perhaps it is because of graphic card calculations, which are Float32 (but again, I am just speculating from not well based knowledge).

In file (I am on Windows, but I think you can find it for your system):
c:\Users\oheil\.julia\packages\Makie\lgPZh\src\makielayout\lineaxis.jl
In line 662 (the original):

    if i.mirror
lastinterval_scaled = scale(tickvalues[end]) - scale(tickvalues[end-1])
nexttick = invscale(scale(tickvalues[end]) + lastinterval_scaled)


change to

    if i.mirror
lastinterval_scaled = scale(tickvalues[end]) - scale(tickvalues[end-1])
nexttick = invscale(scale(Float64(tickvalues[end])) + Float64(lastinterval_scaled))


After the changes saved you need to start a new Julia session and Julia will redo the precompiling automatically.

This is just a quick fix for your specific MWE, hopefully it works for your real data. It is by no means a real solution, because it may have side effects.

It would be great if you would open an issue at GitHub - JuliaPlots/Makie.jl: High level plotting on the GPU. (check if there isn’t already one!) . You can describe your problem and just link to this thread. But of course the issue might be rejected because of the Float32 premise.

Thank you very much!

Hello.
I would need some help again with the same issue.
I have updated to CairoMakie 0.8.8 and the same error appears:
ERROR: InexactError: trunc(Int64, NaN)
The problem is that when I went to edit the file lineaxis.jl it was already updated. So I do not know where the error comes from now.
Thank you very much.

Perhaps it was not the best tip to change the original files. You can overwrite the function like this:

import Makie.get_minor_tickvalues

function get_minor_tickvalues(i::IntervalsBetween, scale::Union{typeof(log), typeof(log2), typeof(log10)}, tickvalues, vmin, vmax)

vals = Float64[]
length(tickvalues) < 2 && return vals
n = i.n

invscale = Makie.inverse_transform(scale)

if i.mirror
firstinterval_scaled = scale(tickvalues[2]) - scale(tickvalues[1])
stepsize = firstinterval_scaled / n
prevtick = invscale(scale(tickvalues[1]) - firstinterval_scaled)
stepsize = (tickvalues[1] - prevtick) / n
v = tickvalues[1] - stepsize
prepend!(vals, v:-stepsize:vmin)
end

for (lo, hi) in zip(@view(tickvalues[1:end-1]), @view(tickvalues[2:end]))
interval = hi - lo
stepsize = interval / n
v = lo
for i in 1:n-1
v += stepsize
push!(vals, v)
end
end

if i.mirror
lastinterval_scaled = scale(tickvalues[end]) - scale(tickvalues[end-1])
nexttick = invscale(scale(Float64(tickvalues[end])) + Float64(lastinterval_scaled))
stepsize = (nexttick - tickvalues[end]) / n
v = tickvalues[end] + stepsize
append!(vals, v:stepsize:vmax)
end

vals
end


Thank you very much. I included your script and it worked. The system required to install Makie because before I was using only CairoMakie.
Besides renaming this function, my current lineaxis.jl file has the line as follows:

nexttick = invscale(scale(Float64(tickvalues[end])) + Float64(lastinterval_scaled))


But that didn’t work. What could be the reason?
Should I take out the “Float64()” edition so that it is in its default state ?
Thank you very much.

On my system I have 3 Makie version installed:
….julia\packages\Makie\bwZTV
….julia\packages\Makie\lgPZh
….julia\packages\Makie\Riyar

I think, this is how the package manager solves different dependencies.

You can do this, but I think, it doesn’t harm if you just let it as is, because the changes are innocent enough.