Legend has different color lines from plot lines
Show older comments
I have the following code to plot some data but the line colors are different from legend's line colors. How I could corrrect it?
for allSS=1:size(scnames,1) ;
nameofsource2open = scnames{allSS,1};
allTCON =[0.3;0.5]
allTECO =[0.2;0.77]
allTENV = [0.56; 0.888]
XallSS2plot = [allTCON(allSS)*0; allTECO(allSS)*(sqrt(3))/2; allTENV(allSS)*(-((sqrt(3))/2));allTCON(allSS)*0]
YallSS2plot = [allTCON(allSS)*1; allTECO(allSS)*(-0.5); allTENV(allSS)*(-0.5);allTCON(allSS)*1]
Xindex2plot = XallSS2plot(:)
Yindex2plot = YallSS2plot(:)
axis , hold on
for i=1:size(scnames,1)
col = rand(i,3)
nameofsource2open = scnames{allSS,1};
hh(i) = plot(XallSS2plot(:,1),YallSS2plot(:,1), 'Color', col(i,:),'LineWidth',2)
legendtext{i} = scnames;
hhh = legend(hh, 'DisplayName',legendtext{i})
linecolors{i} = col(i,:)
legendlinestyles(hhh, {},{},linecolors{i})
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!