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

Cannot plot contours in both CairoMakie and GLMakie #3060

Closed
3 tasks done
tomchor opened this issue Jul 11, 2023 · 8 comments
Closed
3 tasks done

Cannot plot contours in both CairoMakie and GLMakie #3060

tomchor opened this issue Jul 11, 2023 · 8 comments
Labels

Comments

@tomchor
Copy link

tomchor commented Jul 11, 2023

When using CairoMakie to animate contours, I get the following error:

ERROR: LoadError: AssertionError: length(positions) == length(colors)

I posted this on slack a while ago but couldn't solve the issue, so I've decided to post here this time. I also remember someone online somewhere with the same issue as me and no solution, but I can't find that anymore.

Here's the MWE to reproduce this:

using CairoMakie

fig = Figure()
n = Observable(1)

ax = Axis(fig[1, 1])

N = 10
A = randn(N, N, N)
Aₙ = @lift A[:,:,$n]
contour!(ax, Aₙ)

frames = 1:N

record(fig, "mwe.mp4", frames, framerate=14) do frame
    @info "Plotting frame $frame..."
    n[] = frame
end

PS: The error doesn't happen in GLMakie, only usingo CairoMakie. Also for some reason the error seems to happen only in the second frame (i.e. the first frame plots fine), but when I manually try to plot (not animate) the first frame after the fact I get the same error:

julia> n=1
1

julia> current_figure() # hide
Error showing value of type Figure:
ERROR: AssertionError: length(positions) == length(colors)
...
  • are you running newest version (version from docs) ?
  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)
  • What platform + GPU are you on?: up-to-date Manjaro with kernel 6.1.31-2, Julia 1.9.1 (from pre-compiled binaries), but I can reproduce this in all machines I've tried

Here's the full error output:

ERROR: LoadError: AssertionError: length(positions) == length(colors)
Stacktrace:
  [1] draw_multi(primitive::Lines{Tuple{Vector{Point{2, Float32}}}}, ctx::Cairo.CairoContext, positions::Vector{Vec{2, Float32}}, colors::Vector{ColorTypes.RGBA{Float32}}, linewidths::Vector{Float32}, dash::Nothing)
    @ CairoMakie ~/.julia/packages/CairoMakie/zPic1/src/primitives.jl:165
  [2] draw_multi(primitive::Lines{Tuple{Vector{Point{2, Float32}}}}, ctx::Cairo.CairoContext, positions::Vector{Vec{2, Float32}}, colors::Vector{ColorTypes.RGBA{Float32}}, linewidth::Float32, dash::Nothing)
    @ CairoMakie ~/.julia/packages/CairoMakie/zPic1/src/primitives.jl:153
  [3] draw_atomic(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::Union{LineSegments, Lines})
    @ CairoMakie ~/.julia/packages/CairoMakie/zPic1/src/primitives.jl:63
  [4] draw_plot(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::Lines{Tuple{Vector{Point{2, Float32}}}})
    @ CairoMakie ~/.julia/packages/CairoMakie/zPic1/src/infrastructure.jl:108
  [5] draw_plot(scene::Scene, screen::CairoMakie.Screen{CairoMakie.IMAGE}, primitive::Combined{Makie.contour, Tuple{StepRangeLen{Float32, Float64, Float64, Int64}, StepRangeLen{Float32, Float64, Float64, Int64}, Matrix{Float32}}})
    @ CairoMakie ~/.julia/packages/CairoMakie/zPic1/src/infrastructure.jl:113
  [6] cairo_draw(screen::CairoMakie.Screen{CairoMakie.IMAGE}, scene::Scene)
    @ CairoMakie ~/.julia/packages/CairoMakie/zPic1/src/infrastructure.jl:49
  [7] colorbuffer(screen::CairoMakie.Screen{CairoMakie.IMAGE})
    @ CairoMakie ~/.julia/packages/CairoMakie/zPic1/src/screen.jl:307
  [8] colorbuffer(screen::CairoMakie.Screen{CairoMakie.IMAGE}, format::Makie.ImageStorageFormat)
    @ Makie ~/.julia/packages/Makie/iECbF/src/display.jl:355
  [9] recordframe!(io::VideoStream)
    @ Makie ~/.julia/packages/Makie/iECbF/src/ffmpeg-util.jl:242
 [10] Record(func::var"#5#6", figlike::Figure, iter::UnitRange{Int64}; kw_args::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:format, :framerate), Tuple{SubString{String}, Int64}}})
    @ Makie ~/.julia/packages/Makie/iECbF/src/recording.jl:168
 [11] record(func::Function, figlike::Figure, path::String, iter::UnitRange{Int64}; kw_args::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:framerate,), Tuple{Int64}}})
    @ Makie ~/.julia/packages/Makie/iECbF/src/recording.jl:148
 [12] top-level scope
    @ ~/repos/twake/tilted_ridge_simulations/mwe.jl:15
 [13] include(fname::String)
    @ Base.MainInclude ./client.jl:478
 [14] top-level scope
    @ REPL[1]:1
in expression starting at /home/tomas/repos/twake/tilted_ridge_simulations/mwe.jl:15
@tomchor tomchor added the bug label Jul 11, 2023
@tomchor tomchor changed the title CairoMakie throws AssertionError: length(positions) == length(colors) when animating contours CairoMakie fails when animating contours Jul 12, 2023
@aquirosr
Copy link

Are you sure it works fine with GLMakie? I tried it and even though it generates the video, the contours that it shows are wrong in my case except in the first frame.

@tomchor
Copy link
Author

tomchor commented Jul 27, 2023

I hadn't visually checked the output of GLMakie but I guess you're right. Here's what I get for GLMakie with a heatmap as a background:

using GLMakie

fig = Figure()
n = Observable(1)

ax = Axis(fig[1, 1])

N = 10
A = randn(N, N, N)
Aₙ = @lift A[:,:,$n]
heatmap!(ax, Aₙ)
contour!(ax, Aₙ)

frames = 1:N

record(fig, "mwe.mp4", frames, framerate=4) do frame
    @info "Plotting frame $frame..."
    n[] = frame
end
mwe.mp4

So it looks like the contour output doesn't really align with heatmap and doesn't even change in time.

I'm gonna change the title. This seems like kind of a serious bug, I'm surprised that this isn't being reported by anyone else.

@tomchor tomchor changed the title CairoMakie fails when animating contours Cannot plot contours in both CairoMakie and GLMakie Jul 27, 2023
@tomchor
Copy link
Author

tomchor commented Jul 27, 2023

@SimonDanisch are we missing something here? I'm thinking it's weird @aquirosr and I are the only reporting this bug, so maybe the issue is on our end?

@jkrumbiegel
Copy link
Collaborator

Probably an uncaught regression, maybe related to the addition of contour labels (at least I think it has worked before). We don't yet test updating of observables for all plot types, which is how this must have gone through.

@aquirosr
Copy link

I've been doing some tests and this worked up to v0.19.4, included.

@ffreyer
Copy link
Collaborator

ffreyer commented Jul 28, 2023

GLMakie works fine for me on master. Maybe the heatmap is making it hard to see changes?

@tomchor
Copy link
Author

tomchor commented Jul 28, 2023

I only plotted the heatmap to make it easier to see what contour should be doing. Here the output of the same script but without the underlying heatmap. Looks wrong to me:

mwe.mp4

This was also done on master. @ffreyer are you running the same MWE I posted above?

@SimonDanisch
Copy link
Member

Yeah, this is a bug... The line plot observable in contour doesn't update on line updates anymore, it only reacts to label updates ;) Will push a fix shortly!

SimonDanisch added a commit that referenced this issue Jul 28, 2023
@SimonDanisch SimonDanisch mentioned this issue Jul 28, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants