Plots.jl
Plots.jl copied to clipboard
[BUG] Assertion error `total_plotarea_vertical > 0mm`. Plots remains unusable afterwards
Details
Sometimes plot display fails with one of the assertions at https://github.com/JuliaPlots/Plots.jl/blob/4ad4a04a176ba55e69a1263acee8bd0f3034f09a/src/layouts.jl#L342C1-L343C42 and afterwards it's impossible to display plots in the same session.
This bug is weirdly history-dependent, but I've managed to found this reproducer (note that the plot needs to be displayed twice to trigger the bug)
julia> using Plots
julia> function badplot()
plt1 = heatmap(rand(4,4); title = "title")
plt2 = plot(fill(NaN,4), fill(NaN,4))
annotate!([NaN, NaN], [NaN, NaN], Plots.text.(["a", "b"], 12))
plot(plt1, plt2)
end
badplot (generic function with 1 method)
julia> badplot()
julia> badplot()
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: AssertionError: total_plotarea_vertical > 0mm
Stacktrace:
[1] update_child_bboxes!(layout::Plots.GridLayout, minimum_perimeter::Vector{Measures.AbsoluteLength})
@ Plots C:\Users\sternlab\.julia\packages\Plots\3BCH5\src\layouts.jl:343
[2] update_child_bboxes!(layout::Plots.GridLayout)
@ Plots C:\Users\sternlab\.julia\packages\Plots\3BCH5\src\layouts.jl:315
[3] prepare_output(plt::Plots.Plot{Plots.GRBackend})
@ Plots C:\Users\sternlab\.julia\packages\Plots\3BCH5\src\plot.jl:251
[4] display(#unused#::Plots.PlotsDisplay, plt::Plots.Plot{Plots.GRBackend})
@ Plots C:\Users\sternlab\.julia\packages\Plots\3BCH5\src\output.jl:168
[5] display(x::Any)
@ Base.Multimedia .\multimedia.jl:340
[6] #invokelatest#2
@ .\essentials.jl:816 [inlined]
[7] invokelatest
@ .\essentials.jl:813 [inlined]
[8] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
@ REPL C:\Users\sternlab\AppData\Local\Programs\Julia-1.9.0\share\julia\stdlib\v1.9\REPL\src\REPL.jl:305
[9] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
@ REPL C:\Users\sternlab\AppData\Local\Programs\Julia-1.9.0\share\julia\stdlib\v1.9\REPL\src\REPL.jl:287
[10] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
@ REPL C:\Users\sternlab\AppData\Local\Programs\Julia-1.9.0\share\julia\stdlib\v1.9\REPL\src\REPL.jl:557
[11] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
@ REPL C:\Users\sternlab\AppData\Local\Programs\Julia-1.9.0\share\julia\stdlib\v1.9\REPL\src\REPL.jl:285
[12] (::REPL.var"#do_respond#80"{Bool, Bool, REPL.var"#93#103"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
@ REPL C:\Users\sternlab\AppData\Local\Programs\Julia-1.9.0\share\julia\stdlib\v1.9\REPL\src\REPL.jl:899
[13] #invokelatest#2
@ .\essentials.jl:816 [inlined]
[14] invokelatest
@ .\essentials.jl:813 [inlined]
[15] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
@ REPL.LineEdit C:\Users\sternlab\AppData\Local\Programs\Julia-1.9.0\share\julia\stdlib\v1.9\REPL\src\LineEdit.jl:2647
[16] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
@ REPL C:\Users\sternlab\AppData\Local\Programs\Julia-1.9.0\share\julia\stdlib\v1.9\REPL\src\REPL.jl:1300
[17] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
@ REPL .\task.jl:514
It looks like this puts GR in a state where all subsequent calls to GR.inqtext
return NaN
s, which messes up all layouts.
Backends
This bug occurs on ( insert x
below )
Backend | yes | no | untested |
---|---|---|---|
gr (default) | x | ||
pythonplot | x | ||
plotlyjs | |||
pgfplotsx | |||
unicodeplots | |||
inspectdr | |||
gaston |
Versions
Plots.jl version: v1.38.17 and master
Backend version (]st -m <backend(s)>
): 0.72.9
Output of versioninfo()
:
julia> versioninfo()
Julia Version 1.9.0
Commit 8e63055292 (2023-05-07 11:25 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 16 × Intel(R) Core(TM) i7-9800X CPU @ 3.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, skylake-avx512)
Threads: 1 on 16 virtual cores
I have also encountered this bug. It is very frustrating! Kudos for figuring out how to reproduce it!
I am also experiencing this bug.
I'd say the easiest solution would be to error when there is any non-finite value passed to annotate!
But it would be more consistent with the usual Plots
behavior to skip only the annotations at non-finite coordinates
Btw, i do not use annotate!
and i still have this bug. So it's not as simple as a fix to annotate!
(unless it is getting called internally)
julia> using Plots
julia> plot(1:3, -(1:3), yscale=:log10, xlabel="test")
┌ Warning: No strict ticks found
└ @ PlotUtils ~/.julia/packages/PlotUtils/mHQ0Q/src/ticks.jl:191
┌ Warning: No strict ticks found
└ @ PlotUtils ~/.julia/packages/PlotUtils/mHQ0Q/src/ticks.jl:191
┌ Warning: Invalid negative or zero value -1 found at series index 1 for log10 based yscale
└ @ Plots ~/.julia/packages/Plots/rz1WP/src/utils.jl:106
julia> plot(1:3, -(1:3), yscale=:log10, xlabel="test")
┌ Warning: No strict ticks found
└ @ PlotUtils ~/.julia/packages/PlotUtils/mHQ0Q/src/ticks.jl:191
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: AssertionError: total_plotarea_vertical > 0mm
Stacktrace:
[1] update_child_bboxes!(layout::Plots.GridLayout, minimum_perimeter::Vector{Measures.AbsoluteLength})
@ Plots ~/.julia/packages/Plots/rz1WP/src/layouts.jl:343
[2] update_child_bboxes!(layout::Plots.GridLayout)
@ Plots ~/.julia/packages/Plots/rz1WP/src/layouts.jl:315
[3] prepare_output(plt::Plots.Plot{Plots.GRBackend})
@ Plots ~/.julia/packages/Plots/rz1WP/src/plot.jl:251
[4] display(#unused#::Plots.PlotsDisplay, plt::Plots.Plot{Plots.GRBackend})
@ Plots ~/.julia/packages/Plots/rz1WP/src/output.jl:168
[5] display(x::Any)
@ Base.Multimedia ./multimedia.jl:340
Got this error as well, after using twinx().
Plotting negative values in log scale causes this bug. Workaround by plotting without labels.
using Plots
plot(1:5, rand(5); yscale=:log10, xlabel="x", ylabel="y") # ok
# source of error
## ploting negetive with log sacle
pln = plot(1:5,-rand(5); yscale=:log10, xlabel="x", ylabel="y"); # <- note the ; # still ok
display(pln) # ERROR: AssertionError: total_plotarea_horizontal > 0mm
# bug:
pl = plot(1:5, rand(5); yscale=:log10, xlabel="x", ylabel="y"); # <- note the ; # still ok
# should be ok, by fails
display(pl) # ERROR: AssertionError: total_plotarea_horizontal > 0mm
# workaround
plot(1:5, rand(5); yscale=:log10) # plot without labels
plot(1:5, rand(5); yscale=:log10, xlabel="x", ylabel="y") # ok again
Julia version is v1.10.0 Plots version is v1.40.0