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

[BUG] UndefVarError: z_log not defined #4769

Closed
giordano opened this issue Jun 9, 2023 · 8 comments · Fixed by #4770
Closed

[BUG] UndefVarError: z_log not defined #4769

giordano opened this issue Jun 9, 2023 · 8 comments · Fixed by #4770
Labels

Comments

@giordano
Copy link
Contributor

giordano commented Jun 9, 2023

I don't have a simple reproducer at the moment, but I do have a backtrace:

ERROR: UndefVarError: `z_log` not defined
Stacktrace:
  [1] gr_draw_heatmap(series::Plots.Series, x::Vector{Float64}, y::Vector{Float64}, z::Matrix{Float64}, clims::Tuple{Float64, Float64})
    @ Plots ~/.julia/packages/Plots/QWCV6/src/backends/gr.jl:2006
  [2] gr_add_series(sp::Plots.Subplot{Plots.GRBackend}, series::Plots.Series)
    @ Plots ~/.julia/packages/Plots/QWCV6/src/backends/gr.jl:1764
  [3] gr_display(sp::Plots.Subplot{Plots.GRBackend}, w::Measures.AbsoluteLength, h::Measures.AbsoluteLength, vp_canvas::Plots.GRViewport{Float64})
    @ Plots ~/.julia/packages/Plots/QWCV6/src/backends/gr.jl:964
  [4] (::Plots.var"#506#507"{Int64, Int64, Plots.GRViewport{Float64}})(sp::Plots.Subplot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/QWCV6/src/backends/gr.jl:688
  [5] foreach(f::Plots.var"#506#507"{Int64, Int64, Plots.GRViewport{Float64}}, itr::Vector{Plots.Subplot})
    @ Base ./abstractarray.jl:3073
  [6] gr_display(plt::Plots.Plot{Plots.GRBackend}, dpi_factor::Float64)
    @ Plots ~/.julia/packages/Plots/QWCV6/src/backends/gr.jl:688
  [7] #545
    @ ~/.julia/packages/Plots/QWCV6/src/backends/gr.jl:2052 [inlined]
  [8] withenv(::Plots.var"#545#546"{Plots.Plot{Plots.GRBackend}, Float64}, ::Pair{String, String}, ::Vararg{Pair{String, String}})
    @ Base ./env.jl:197
  [9] _show(io::IOStream, #unused#::MIME{Symbol("image/png")}, plt::Plots.Plot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/QWCV6/src/backends/gr.jl:2047
 [10] #invokelatest#2
    @ ./essentials.jl:816 [inlined]
 [11] invokelatest
    @ ./essentials.jl:813 [inlined]
 [12] show
    @ ~/.julia/packages/Plots/QWCV6/src/output.jl:232 [inlined]
 [13] #344
    @ ~/.julia/packages/Plots/QWCV6/src/output.jl:6 [inlined]
 [14] open(::Plots.var"#344#345"{Plots.Plot{Plots.GRBackend}}, ::String, ::Vararg{String}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./io.jl:395
 [15] open
    @ ./io.jl:392 [inlined]
 [16] png(plt::Plots.Plot{Plots.GRBackend}, fn::String)
    @ Plots ~/.julia/packages/Plots/QWCV6/src/output.jl:6
 [17] savefig(plt::Plots.Plot{Plots.GRBackend}, fn::String)
    @ Plots ~/.julia/packages/Plots/QWCV6/src/output.jl:149
 [18] savefig(fn::String)
    @ Plots ~/.julia/packages/Plots/QWCV6/src/output.jl:154
 [19] top-level scope
    @ REPL[63]:1

z_log at

z_log, gr_z_normalized_log_scaled(scale, z, clims)
is undefined.

@giordano giordano added the bug label Jun 9, 2023
@giordano
Copy link
Contributor Author

giordano commented Jun 9, 2023

Ah, I finally got a small-contained reproducer:

x = y = collect(-10:0.01f0:10);
fig = heatmap(x, y, hypot.(x', y); colorbar_scale=:log10)

@BeastyBlacksmith
Copy link
Member

BeastyBlacksmith commented Jun 9, 2023

What would you expect are the limits for the colorbar in this case? I am tempted to just throw an error.

@giordano
Copy link
Contributor Author

giordano commented Jun 9, 2023

I am tempted to just throw an error.

Why? It works if x, y are Float64, it seems to fail only with Float32, and the offending line has that z_log which is clearly undefined.

@david-macmahon
Copy link
Contributor

There are two problems demonstrated in the reproducer from @giordano . One is taking the log of zero. The other one, which I think is more relevant to this issue, is "z_log not defined". I think the latter problem is actually caused by irregular spacing of the x (and y) values combined with colobar_scale=:log10. Here is a simpler example:

heatmap([1,2,3], [1,2], rand(2,3), colorbar_scale=:log10) # works
heatmap([1,2,4], [1,2], rand(2,3), colorbar_scale=:log10) # z_log not defined
heatmap([1,2,4], [1,2], rand(2,3)) # works

I only tried this with the GR backend, so I don't know whether it's backend-specific.

@giordano
Copy link
Contributor Author

giordano commented Jun 9, 2023

It works if x, y are Float64

Well, "works" was a bit of a stretch: I don't get any error, but I also get an empty plot. It's solved if setting clims excplicitly.

@david-macmahon
Copy link
Contributor

It works if x, y are Float64

Well, "works" was a bit of a stretch: I don't get any error, but I also get an empty plot. It's solved if setting clims excplicitly.

That's because of the zero value(s?) in your z. If you use hypot.(x', y).+1 it won't be blank. I guess it's a bug that the whole plot is blank instead of just where z <= 0.

@giordano
Copy link
Contributor Author

giordano commented Jun 9, 2023

Right. My actual data didn't have zeros, it started from 1, the example I used here was too simplified, the zero is a red herring.

@BeastyBlacksmith
Copy link
Member

Can you check #4770?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants