Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_minor_tickvalues makes a range with step=0 because of numerical precision when values are essentially the same except for numerical error #4593

Open
3 tasks
rekabrnalla opened this issue Nov 15, 2024 · 0 comments
Labels
Axis related to `Axis()` objects bug Makie Backend independent issues (Makie core)

Comments

@rekabrnalla
Copy link

  • what version of Makie are you running? (]st -m Makie)
    [ee78f7c6] Makie v0.21.16

  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)
    I'm still working on a MWE. It happens during a massive GUI with Observables. It is difficult to determine what triggers it. I think the problem is I have a spherical conversion that takes a vector at the origin and sweeps the phi values for a given theta. At the Theta=0 for all phi points, the answer should be all the same, but because of numerical differences, they are off by very small differences especially when they are converted to dB. This leads the minor tick values to probably fail some check where it assumes in this function that major tickmarks can't be the same on the axis, but because there is such a miniscule difference, It calculates a range step for the minor steps which is zero and then attempts to make a range out of this which it errors on. You can see in the code I pasted, there is a missed assumption and no check for when stepsize=0.

Here is a partial Error Stacktrace. Because of the observables I don't even get pointed to the original offender, but I can guess and commented out that plot and the error went away, so I'm pretty sure my description above is correct.

Error showing value of type Figure:
ERROR: ArgumentError: range step cannot be zero
Stacktrace:
  [1] (::Colon)(start::Float64, step::Float64, stop::Float64)
    @ Base .\twiceprecision.jl:394
  [2] get_minor_tickvalues(i::IntervalsBetween, scale::Function, tickvalues::Vector{Float64}, vmin::Float64, vmax::Float64)
    @ Makie D:\JULIA_DEPOT_PATH\.julia\packages\Makie\pFPBw\src\makielayout\lineaxis.jl:744
  [3] (::Makie.var"#1612#1626"{Attributes, Observable{Vector{Float64}}, Observable{Tuple{Float64, Float64}}})(tickvalues::Vector{Float64}, minorticks::IntervalsBetween)
    @ Makie D:\JULIA_DEPOT_PATH\.julia\packages\Makie\pFPBw\src\makielayout\lineaxis.jl:437
  [4] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\essentials.jl:892
  [5] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:889
  [6] (::Observables.OnAny)(value::Any)
    @ Observables D:\JULIA_DEPOT_PATH\.julia\packages\Observables\YdEbO\src\Observables.jl:420
...Stuff Deleted....
  • What platform + GPU are you on?
    Windows

The problem is here

# for log scales, we need to step in log steps at the edges
function get_minor_tickvalues(i::IntervalsBetween, scale::LogFunctions, 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(tickvalues[end]) + lastinterval_scaled)
        stepsize = (nexttick - tickvalues[end]) / n
        v = tickvalues[end] + stepsize
        append!(vals, v:stepsize:vmax)                                                          <<<==== **ERROR because step-size is zero** 
    end

    vals
end

I'll see if I can find a MWE.

Summary. Values in the Y axis for scatterlines are essentially the same value, but due to numerical precision problems in the math to get those values, the major tickmarks are essentially the same. So any math that gets calculated on them results in a zero stepsize. This goes to a v:stepsize:vmax range evaluation which blows chunks. Need some protection or a change in assumptions.

@ffreyer ffreyer added Axis related to `Axis()` objects Makie Backend independent issues (Makie core) labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Axis related to `Axis()` objects bug Makie Backend independent issues (Makie core)
Projects
None yet
Development

No branches or pull requests

2 participants