Plot multiple Lines and keep them in one handle
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
bigsmile96
il 20 Lug 2017
Commentato: Javier Cabello
il 29 Mag 2020
Hi everybody,
I want to plot many (round about 30.000) 2D-lines in a plot. A line has only change in y-axis.
For example:
tolerance_1 = [2 3 4 5 6 7 8];
tolerance_2 = [1 2 3 4 5 6 7];
x = [1 2 3 4 5 6 7];
line1 = plot ([x(1) x(1)], [tolerance_1(1) tolerance_2(1)], 'r-');
It is no problem to plot all the lines with a for-loop. But I need to keep for all the lines a handle so I can set the lines visible and invisible. When I create a vector with the length of the number of lines (round about 30.000) and fill it with all the handles, my MATLAB crashes. Is there a possibility to get a single handle to all the lines?
I tried something like that:
mylines = plot([x x],[tolerance_1 tolerance_2],'r-')
But this does not work because the single lines are connected.
Does anybody know a solution?
Thank you very much and have a nice day. :-)
2 Commenti
Adam
il 20 Lug 2017
How can you possibly make any sense of a plot with 30,000 lines on it? It sounds like it needs a rethink of what you are doing. Each line will be its own graphics object unless you connect them all to be a single line, but I thought the point of what you wanted was to be able to switch off (make invisible) individual lines anyway?
Stephen23
il 20 Lug 2017
Modificato: Stephen23
il 20 Lug 2017
30000 lines in one figure? At typical modern monitor sizes (e.g. 1920x1080) those lines would be totally indistinguishable. You would need a monitor with well more than ten times higher resolution... does anything like that even exist? I guess you have a rather large IT budget.
Risposta accettata
Stephen23
il 20 Lug 2017
Modificato: Stephen23
il 20 Lug 2017
Plotting in a loop is a waste of MATLAB:
tol1 = [2 3,4,5,6,7,8];
tol2 = [1,2,3,4,5,6,7];
x = [1,2,3,4,5,6,7];
lnh = plot([x;x],[tol1;tol2],'*-');
producing:

3 Commenti
Stephen23
il 20 Lug 2017
@bigsmile96: note that you might also like to read about the line ColorOrder:
and see the "Examples" for how to change it:
Javier Cabello
il 29 Mag 2020
Awesome! I also had a similar problem, just multple straight lines in a plot. Simple and elegant solution, without bending myself backward (and crashing the computer) with loops.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!