Plot multiple Lines and keep them in one handle
조회 수: 6 (최근 30일)
이전 댓글 표시
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
Adam
2017년 7월 20일
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
2017년 7월 20일
편집: Stephen23
2017년 7월 20일
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.
채택된 답변
Stephen23
2017년 7월 20일
편집: Stephen23
2017년 7월 20일
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
Stephen23
2017년 7월 20일
@bigsmile96: note that you might also like to read about the line ColorOrder:
and see the "Examples" for how to change it:
Javier Cabello
2020년 5월 29일
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.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!