Replies: 12 comments
-
You could use a Vector{Point} instead? That would make sure x and y update synchronously. |
Beta Was this translation helpful? Give feedback.
-
This does not really solve the issue. Sometimes, one might wish to also update other attributes (e.g. the color of each point in a scatter plot). Fake dependencies work but I was just wondering whether there is a more elegant solution. |
Beta Was this translation helpful? Give feedback.
-
Update: I have noticed that for rendering with `arrows(points, directions; kwargs...)`
`arrows(x, y, u, v)`
`arrows(x::AbstractVector, y::AbstractVector, u::AbstractMatrix, v::AbstractMatrix)`
`arrows(x, y, z, u, v, w)` |
Beta Was this translation helpful? Give feedback.
-
Yeaah, this is annoying ... using Makie
px = zeros(1)
py = zeros(1)
px_n = Node(px)
py_n = Node(py)
scatter(px_n, py_n) |> display
for t in 1:10
# generate random dummy data (number of points may vary over time)
n_points = rand(5:10)
empty!(px); empty!(py);
append!(px, rand(n_points))
append!(py, rand(n_points))
py_n[] = py_n[]
sleep(0.1)
end |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply. I guess that is a workaround that should work. Are there any plans to support more synchronized update of nodes (e.g. by locking the scene)? Or are there other reasons not to support this? |
Beta Was this translation helpful? Give feedback.
-
I should have never allowed to update individual vectors :D This was a bad design decision... The plan is to support this in the future: particles = Buffer(colors = colors, positions = positions)
scatter(particles)
# Or
particles = [(color=color, position=position), (...)]
scatter(particles) ... And internally map to this! |
Beta Was this translation helpful? Give feedback.
-
This workaround does not seem to work for using Makie
px = zeros(1)
py = zeros(1)
pu = zeros(1)
pv = zeros(1)
px_n = Node(px)
py_n = Node(py)
pu_n = Node(pu)
pv_n = Node(pv)
arrows(px_n, py_n, pu_n, pv_n) |> display
for t in 1:10
# generate random dummy data (number of points may vary over time)
n_points = rand(5:10)
empty!(px); empty!(py); empty!(pu); empty!(pv)
append!(px, rand(n_points))
append!(py, rand(n_points))
append!(pu, rand(n_points))
append!(pv, rand(n_points))
py_n[] = py_n[]
sleep(0.1)
end |
Beta Was this translation helpful? Give feedback.
-
Hm, that's because there is an extra level of indirection to construct the points out of x and y, I think... using Makie
pxy = [Point2f0(0)]
puv = [Vec2f0(1)]
pxy_n = Node(pxy)
puv_n = Node(puv)
arrows(pxy_n, puv_n) |> display
for t in 1:10
# generate random dummy data (number of points may vary over time)
n_points = rand(5:10)
empty!(pxy); empty!(puv);
append!(pxy, rand(Point2f0, n_points))
append!(puv, rand(Vec2f0, n_points))
pxy_n[] = pxy_n[]
sleep(0.1)
end |
Beta Was this translation helpful? Give feedback.
-
Okay, that seems to work. Really subtle... |
Beta Was this translation helpful? Give feedback.
-
... bump this: I would like to update mesh coordinates and mesh connectivity at the same time. However what worked for arrows didn't work for mesh... |
Beta Was this translation helpful? Give feedback.
-
Could this be related? https://discourse.julialang.org/t/cairomakie-assertionerror-length-positions-length-colors-when-trying-to-record/61001/4 |
Beta Was this translation helpful? Give feedback.
-
Here's another instance of this error for which I cannot get @SimonDanisch's workaround to work. Instead, I see the following error: Click to expand stacktraceERROR: DimensionMismatch: arrays could not be broadcast to a common size; got a dimension with lengths 2 and 3
Stacktrace:
[1] _bcs1
@ ./broadcast.jl:543 [inlined]
[2] _bcs
@ ./broadcast.jl:537 [inlined]
[3] broadcast_shape
@ ./broadcast.jl:531 [inlined]
[4] combine_axes
@ ./broadcast.jl:512 [inlined]
[5] combine_axes (repeats 2 times)
@ ./broadcast.jl:511 [inlined]
[6] instantiate
@ ./broadcast.jl:294 [inlined]
[7] materialize
@ ./broadcast.jl:887 [inlined]
[8] offset_bezierpath(atlas::Makie.TextureAtlas, bp::Makie.BezierPath, scale::Vector{GeometryBasics.Vec{2, Float32}}, offset::Vector{GeometryBasics.Vec{2, Float32}})
@ Makie ~/.julia/packages/Makie/gAmAB/src/utilities/texture_atlas.jl:513
[9] offset_marker(atlas::Makie.TextureAtlas, marker::Makie.BezierPath, font::FreeTypeAbstraction.FTFont, markersize::Vector{GeometryBasics.Vec{2, Float32}}, markeroffset::Vector{GeometryBasics.Vec{2, Float32}})
@ Makie ~/.julia/packages/Makie/gAmAB/src/utilities/texture_atlas.jl:517
[10] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base ./essentials.jl:823
[11] invokelatest(::Any, ::Any, ::Vararg{Any})
@ Base ./essentials.jl:820
[12] (::Observables.MapCallback)(value::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:431
[13] #invokelatest#2
@ ./essentials.jl:823 [inlined]
[14] invokelatest
@ ./essentials.jl:820 [inlined]
[15] notify
@ ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:169 [inlined]
[16] setindex!(observable::Observables.Observable, val::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:86
[17] (::Observables.MapCallback)(value::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:431
[18] #invokelatest#2
@ ./essentials.jl:823 [inlined]
[19] invokelatest
@ ./essentials.jl:820 [inlined]
[20] notify
@ ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:169 [inlined]
[21] setindex!(observable::Observables.Observable, val::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:86
[22] (::Observables.SetindexCallback)(x::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:111
[23] #invokelatest#2
@ ./essentials.jl:823 [inlined]
[24] invokelatest
@ ./essentials.jl:820 [inlined]
[25] notify
@ ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:169 [inlined]
[26] setindex!(observable::Observables.Observable, val::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:86
[27] (::Observables.MapCallback)(value::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:431
[28] #invokelatest#2
@ ./essentials.jl:823 [inlined]
[29] invokelatest
@ ./essentials.jl:820 [inlined]
[30] notify
@ ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:169 [inlined]
[31] setindex!(observable::Observables.Observable, val::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:86
[32] (::Observables.SetindexCallback)(x::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:111
[33] #invokelatest#2
@ ./essentials.jl:823 [inlined]
[34] invokelatest
@ ./essentials.jl:820 [inlined]
[35] notify
@ ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:169 [inlined]
[36] setindex!(observable::Observables.Observable, val::Any)
@ Observables ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:86
[37] (::var"#update#75"{Vector{Vector{Float64}}, Observables.Observable{Vector{Float32}}, Observables.Observable{Vector{GeometryBasics.Point{2, Float32}}}})(time::Int64)
@ Main ~/worktree/BugReports/MakieMarkersizeUpdate.jl/main.jl:7
[38] #invokelatest#2
@ ./essentials.jl:823 [inlined]
[39] invokelatest
@ ./essentials.jl:820 [inlined]
[40] notify
@ ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:169 [inlined]
[41] setindex!
@ ~/.julia/packages/Observables/PHGQ8/src/Observables.jl:86 [inlined]
[42] main()
@ Main ~/worktree/BugReports/MakieMarkersizeUpdate.jl/main.jl:28
[43] top-level scope
@ REPL[7]:1
[44] top-level scope
@ ~/.julia/packages/Infiltrator/r3Hf5/src/Infiltrator.jl:710 Interestingly, unlike in the discourse thread linked by @aramirezreyes setting the observable to the maximum array size from the beginning does not do the trick; only if using Makie: Makie
using GLMakie: GLMakie
function foo!(axis, points, time::Makie.Observable)
filtered_points = Makie.Observable(Makie.Point2f[])
markersize = Makie.Observable(Float32[])
function update(time)
copy!(filtered_points[], [Makie.Point2f(p) for p in first(points, time)])
copy!(markersize[], [5 * t for t in range(1, time; length=time)])
@assert length(filtered_points[]) == length(markersize[]) # <- this never fails
markersize[] = markersize[]
end
# fill all the observables with the correct data
update(time[])
# register callback
Makie.on(update, time)
Makie.scatter!(axis, filtered_points; markersize)
end
function main()
points = [rand(2) for _ in 1:10]
time = Makie.Observable(10)
figure = Makie.Figure()
axis = Makie.Axis(figure[1, 1], limits=((0, 1), (0, 1)))
foo!(axis, points, time)
display(figure)
for t in eachindex(points)
time[] = t
sleep(0.1)
end
end |
Beta Was this translation helpful? Give feedback.
-
I am trying to visualize a sequence of 2D scatter plots using the
Node
/Observable
feature to achieve fast update rates. However, I run into errors if the number of points changes over time as the plotting function will fail in cases where the number of x and y coordinates is not the same. Is there a way lock the scene update until all Nodes are updated?Here is a MWE
Do I have to introduce fake-dependencies between nodes to make this work? Or is there some sort of mutex for Makie scenes?
Beta Was this translation helpful? Give feedback.
All reactions