manually enter legend details
이전 댓글 표시
I have 9 curves on a plot. 3 different colors x 3 (solid lines, dotted lines etc). However Instead of crowding my legend with 9 entries, I'd like to depict each color - their meaning (example red - 30-70Hz, blue - 20-50hz etc) and separately the meaning of dotted lines (training set), solid lines (test set) etc. How do I do this in Matlab ?
채택된 답변
추가 답변 (1개)
Use the legend() function at the end of your plot with and empty string entry. Then, plot empty lines according to the final legend output you desire. Use 'DisplayName' to properly name the lines on the final legend output.
x = linspace(0,1, 10);
cols = ["red", "blue", "green"];
line_type = ["-", "--", ":"];
for i = 1:9
y = x + i/3;
col_i = cols(mod(i,3) + 1);
line_type_i = line_type(mod(i,3) + 1);
plot(x,y, line_type_i, 'Color', col_i)
hold on
end
legend('','Location', 'eastoutside')
col_names = ["30-70Hz", "20-50Hz", "40-80hz"];
for j =1:length(col_names)
plot([NaN NaN], [NaN NaN], 'Color', cols(j), 'DisplayName', col_names(j))
end
line_names = ["training set", "testing set", "simulation"];
for j =1:length(line_type)
plot([NaN NaN], [NaN NaN],line_type(j), 'Color', 'k', 'DisplayName', line_names(j))
end
hold off
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
