Plot multiple Lines and keep them in one handle
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
bigsmile96
am 20 Jul. 2017
Kommentiert: Javier Cabello
am 29 Mai 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 Kommentare
Adam
am 20 Jul. 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
am 20 Jul. 2017
Bearbeitet: Stephen23
am 20 Jul. 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.
Akzeptierte Antwort
Stephen23
am 20 Jul. 2017
Bearbeitet: Stephen23
am 20 Jul. 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 Kommentare
Stephen23
am 20 Jul. 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
am 29 Mai 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.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!