Eliminate Duplicates in a Legend
46 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Douglas Anderson
le 28 Avr 2021
Commenté : Douglas Anderson
le 28 Avr 2021
Hello!
I am trying to plot 27 points that fit into 12 categories and then have a legend showing what symbols are used for each of the categories. I'm probably overcomplicating this whole thing, but here is the code (abbreviated)
figure
for n = 1:num_stopes % There are 27 of them
ppv = PPV(n); % Vibration Level
this_month = month(n); % Month Number
recep = str2double(regexprep(receptor_list{n},'R','')); % Get Receptor Number. receptor_list is cell array
switch recep % There are 12 receptors
case recep_nums(1)
plot(this_month,ppv,'Marker','o','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','r','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(2)
plot(this_month,ppv,'Marker','o','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','g','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(3)
plot(this_month,ppv,'Marker','o','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','b','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(4)
plot(this_month,ppv,'Marker','o','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','m','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(5)
plot(this_month,ppv,'Marker','o','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','c','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(6)
plot(this_month,ppv,'Marker','o','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','y','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(7)
plot(this_month,ppv,'Marker','diamond','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','r','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(8)
plot(this_month,ppv,'Marker','diamond','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','g','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(9)
plot(this_month,ppv,'Marker','diamond','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','b','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(10)
plot(this_month,ppv,'Marker','diamond','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','m','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(11)
plot(this_month,ppv,'Marker','diamond','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','c','DisplayName',['Receptor ',num2str(recep)]);
case recep_nums(12)
plot(this_month,ppv,'Marker','diamond','LineStyle','none','MarkerEdgeColor','k','MarkerFaceColor','y','DisplayName',['Receptor ',num2str(recep)]);
end
hold on
end
legend('show');
ylim([0 2.5]);
ylabel('PPV (in/s)')
xlabel('Month')
title('PPV for Receptors Close to Early Stopes')
Here is the resultant figure and legend:
Thank you for any help!
Doug Anderson
0 commentaires
Réponse acceptée
DGM
le 28 Avr 2021
Because you're looping through the list of datapoints and plotting each one individually, there are not 12 objects, but num_stopes objects. The better way to do this would be to plot all the datapoints associated with a given receptor at once. In other words, instead of building a loop structure like this:
for n=1:num_stopes
% plot this one point
end
do something like
for n=1:num_receptors
% find all points associated with this receptor
% plot this subset of points
end
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!