Hello,
I am trying to plot 2 histograms in the same figure using Makie,
f, ax1, h1 = hist(df1[:, “AF”])
h2 = hist!(ax1, df2[:, “AF”])
f
but
TypeError: non-boolean (Missing) used in boolean context
However, this codes work
x = range(0, 10, length=100)
f2, ax, l1 = lines(x, sin)
l2 = lines!(ax, x, cos)
f2
I don’t understand why my code doesn’t work. I plot an histogram then I use the ! to tell it to add the second serie on the same figure. Why is it looking for a boolean?
Thank you
nilshg
September 8, 2023, 9:41am
2
This works fine for me:
julia> using CairoMakie
julia> f, ax1, h1 = hist(rand(100))
julia> hist!(ax1, 2*rand(100))
Combined{Makie.hist, Tuple{Vector{Float64}}}
julia> f
and shows the importance to create minimum working examples for errors that you want help with - what is df1[:, "AF"]
? What is the actual stacktrace you are getting?
Sorry I assumed it was a stupid syntax error on my part, here is the stack trace
pick_hist_edges (::Vector{Union{Missing, Float64}}, ::Int64) @hist.jl:146
map #136 @scenes.jl:185 [inlined]
map (::typeof(Makie.pick_hist_edges), ::MakieCore.Combined{Makie.hist, Tuple{Vector{Union{Missing, Float64}}}}, ::Observables.Observable{Vector{Union{Missing, Float64}}}, ::Observables.Observable{Any}) @scenes.jl:182
plot! (::MakieCore.Combined{Makie.hist, Tuple{Vector{Union{Missing, Float64}}}}) @hist.jl:163
plot! (::Makie.Scene, ::Type{MakieCore.Combined{Makie.hist, Tuple{Vector{Union{Missing, Float64}}}}}, ::MakieCore.Attributes, ::Tuple{Observables.Observable{Vector{Union{Missing, Float64}}}}, ::Observables.Observable{Tuple{Vector{Union{Missing, Float64}}}}) @interfaces.jl:398
var"plot !#192 " (::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.plot!), ::Makie.Scene, ::Type{MakieCore.Combined{Makie.hist}}, ::MakieCore.Attributes, ::Vector{Union{Missing, Float64}}) @interfaces.jl:310
plot! @interfaces.jl:275 [inlined]
var"plot #2000" (::NamedTuple{(), Tuple{}}, ::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.plot), ::Type{MakieCore.Combined{Makie.hist}}, ::GridLayoutBase.GridPosition, ::Vector{Union{Missing, Float64}}) @figureplotting.jl:98
plot (::Type{MakieCore.Combined{Makie.hist}}, ::GridLayoutBase.GridPosition, ::Vector{Union{Missing, Float64}}) @figureplotting.jl:72
var"#hist #879" (::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Makie.hist), ::GridLayoutBase.GridPosition, ::Vararg{Any}) @recipes.jl:34
hist (::GridLayoutBase.GridPosition, ::Vararg{Any}) @recipes.jl:33
top-level scope @Local: 6
I am trying to plot 2 dataframeS, I imported them so
df1=CSV.read(“/media/alessandro/Storage/MA/comparing_GATK_and_bbtools/bbtools_allele_fraction.txt”, DataFrame; header = false)
rename!(df1,[:Column1] .=> [:AF])
Here it what they look like
1
1
1
0.063
0.056
0.056
0.15
0.25
0.136
0.136
roughly 2 million lines, datatype is Float64 which is correct.
hope this gives you all the info you asked for
EDIT:
I tried to copy your solution
using CairoMakie
f, ax1, h1=hist(df1[:, “AF”])
hist!(ax1, df2[:, “AF”] )
Combined{Makie.hist, Tuple{Vector{Float64}}}
f
but this returns
TypeError: non-boolean (Missing) used in boolean context
pick_hist_edges (::Vector{Union{Missing, Float64}}, ::Int64) @hist.jl:146
map #136 @scenes.jl:185 [inlined]
map (::typeof(Makie.pick_hist_edges), ::MakieCore.Combined{Makie.hist, Tuple{Vector{Union{Missing, Float64}}}}, ::Observables.Observable{Vector{Union{Missing, Float64}}}, ::Observables.Observable{Any}) @scenes.jl:182
plot! (::MakieCore.Combined{Makie.hist, Tuple{Vector{Union{Missing, Float64}}}}) @hist.jl:163
plot! (::Makie.Scene, ::Type{MakieCore.Combined{Makie.hist, Tuple{Vector{Union{Missing, Float64}}}}}, ::MakieCore.Attributes, ::Tuple{Observables.Observable{Vector{Union{Missing, Float64}}}}, ::Observables.Observable{Tuple{Vector{Union{Missing, Float64}}}}) @interfaces.jl:398
var"plot !#192 " (::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.plot!), ::Makie.Scene, ::Type{MakieCore.Combined{Makie.hist}}, ::MakieCore.Attributes, ::Vector{Union{Missing, Float64}}) @interfaces.jl:310
plot! @interfaces.jl:275 [inlined]
var"plot !#1458 " (::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.plot!), ::Makie.Axis, ::Type{MakieCore.Combined{Makie.hist}}, ::MakieCore.Attributes, ::Vector{Union{Missing, Float64}}) @axis.jl:792
plot! @axis.jl:779 [inlined]
var"plot !#1459 " (::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(MakieCore.plot!), ::Type{MakieCore.Combined{Makie.hist}}, ::Makie.Axis, ::Vector{Union{Missing, Float64}}) @axis.jl:809
plot! (::Type{MakieCore.Combined{Makie.hist}}, ::Makie.Axis, ::Vector{Union{Missing, Float64}}) @axis.jl:807
var"#hist !#880 " (::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(Makie.hist!), ::Makie.Axis, ::Vararg{Any}) @recipes.jl:38
hist! (::Makie.Axis, ::Vararg{Any}) @recipes.jl:37
top-level scope @Local: 4
Am I right to suspect there might be an unexpected value in my dataframes?
nilshg
September 8, 2023, 10:03am
4
Yes, you probably have missing values in df2[:, "AF"]
:
julia> x = rand([missing; range(-1, 1, 100)], 10_000);
julia> f, ax1, h1 = hist(x); hist!(ax1, y); f
ERROR: TypeError: non-boolean (Missing) used in boolean context
1 Like
It’s probably the issue, any idea why the error says it’s a boolean problem? just out of curiosity
EDIT: your solution works like a charm now that I cleaned the input data. Though now I need to investigate why data are missing, but that’s not an issue with Julia
nilshg
September 8, 2023, 11:14am
6
You’d have to check the source code to see what is happening, but missing
propagates through comparisons like <
or ==
so presumably at some point the histogram wants to check whether a number is below the bin edge value to determine whether to add it to the count for that bin and something like this happens:
julia> if missing < bin_edge
current_bin += 1
end
ERROR: TypeError: non-boolean (Missing) used in boolean context
jules
September 8, 2023, 11:46am
7
This could use a better error message higher up the stack. Could you please open an issue?