Plotting - Control Legend
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Cillian Hayde
le 16 Fév 2021
Réponse apportée : Jemima Pulipati
le 19 Fév 2021
Hi,
I have data coming in and I am plotting it.
Is there a way to preassign a legend so that the marker face colour is assigned to the condition it represents.
For instance, I would like the graph to be like the picture attached, but the legend to be there at the beginning of the plot and for the descriptions "Item X" to be fixed to the specified marker i.e.
- Yellow = Item A
- Magenta = Item D
etc
An example codeblock to test is provided below. It is based on what I have.
clf
MarkerFaceColor{1} = [1 1 0]; % YELLOW MarkerFaceColor is item A
MarkerFaceColor{2} = [1 1 1]; % White MarkerFaceColor is item B
MarkerFaceColor{3} = [0 1 0]; % Green MarkerFaceColor is item C
MarkerFaceColor{4} = [1 0 1]; % Magenta MarkerFaceColor is item D
Black = [0,0,0];
x = 1:1:10;
y = repelem(1,10);
Color = [1 3 4 2 2 3 1 4 3 3];
legend() %? MarkerFaceColor - Item X
for i = 1:1:10
pause(1)
plot(x(i),y(i),"Marker","o","MarkerEdgeColor",Black,"MarkerFaceColor",MarkerFaceColor{Color(i)},"MarkerSize",17)
legend()%? MarkerFaceColor - Item X
ylim([0 2])
hold on
end
0 commentaires
Réponse acceptée
Jemima Pulipati
le 19 Fév 2021
Hello,
From my understanding, you want to customise the colors in the legend.
The following answers from the community might be of relevance to you.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!