Change color order of legend
이전 댓글 표시
I have a number of parameters that I want to plot or not plot based on whether the user selects them in a GUI. If a parameter isn't selected, I reassign the values to NaN so they don't plot. Here I'll just include 3 parms as an example. I also fill legend text based on the selections.
ind = 1;
if flag1; legendtext{ind}='y1'; ind=ind+1; else y1 = y1*NaN; end
if flag2; legendtext{ind}='y2'; ind=ind+1; else y2 = y2*NaN; end
if flag3; legendtext{ind}='y3'; ind=ind+1; else y3 = y3*NaN; end
plot(h, x1,y1,x2,y2,x3,y3)
legend(h, legendtext)
The plot always plots y1 as blue, y2 as green and y3 as red because if any are NaNs, they act as placeholders for the colors. But if flag1 or flag2 is not set then the legend colors do not match the plot colors. I could add plot(h,xi,yi) to every test, but I want to know if I there is another way.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!