Makie: Multiple lines in a loop

Hello!

I am plotting several lines in a Makie Figure this way:
p1=lines!(positions1)
p2=lines!(positions2)

I need to access p$i after that, and I may have to display ten of them. I’d like to have these lines! in a loop and access the variables with an index. It looks like I can’t have a vector with the “lines” type. How can I do to index these lines?

Or is there any other way to consider the problem? I want the lines to have different colors, and I want to be able to modify the lines interactively with the mouse (which works with one line, using p1, this is why I think I need p1 to p10 if I want to be able to interact with 10 lines).

Thank you!

You can pass an array of colors and use NaN to separate them.
If you want better performance and dont need good line joints, you should use linesegments.

You can also create an array of lines, not sure why you say you cant?
line_plot_objects = map(lines!, positions).
In general, one plot is preferred, over multiple ones, since each plot object has some rendering overhead.

1 Like

Thank you for your help. I am new to Julia and Makie so I didn’t even know map!
However, in my case positions is an observable, and in that case it seems that line_plot_objects becomes an observable itself and I can’t use it for later interaction.

I think I will rather find a way to select scatters and lines one by one and interact with the one selected.

Thanks again