Why is the legend in my MATLAB code showing only one color for all the items, even though the colors are different in the parallel coordinates graph?

3 次查看(过去 30 天)
% Define colors for each alphaclass
colors = {[1 0 0], [0 1 0], [0 0 1], [1 0 1]}; % RGB values for red, green, blue, magenta
alphaClasses = repelem(1:4, numImages/4);
% Create a parallel coordinates plot for the projected images
figure;
for i = 1:length(alphaClasses)
line(1:numComponents, projectedImages(i,:), 'Color', colors{alphaClasses(i)});
end
xlabel('AB');
ylabel('CD');
title('Parallel Coordinates Plot of Projected Images');
legend('ab', 'cd', 'ef', 'gh', 'Location', 'northeast');

回答(1 个)

Dyuman Joshi
Dyuman Joshi 2023-4-16
Because there is only one line in the plot, as the plot is getting overwritten in each iteration. You need to use the command
"hold on" to retain all the plots in the same figure.
figure
hold on
for i = 1:length(alphaClasses)
line(1:numComponents, projectedImages(i,:), 'Color', colors{alphaClasses(i)});
end
%use hold off after the loop if necessary

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by