Eliminate Duplicates in a Legend

52 ビュー (過去 30 日間)
Douglas Anderson
Douglas Anderson 2021 年 4 月 28 日
コメント済み: Douglas Anderson 2021 年 4 月 28 日
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

採用された回答

DGM
DGM 2021 年 4 月 28 日
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
  1 件のコメント
Douglas Anderson
Douglas Anderson 2021 年 4 月 28 日
Yes! Thank you, makes total sense!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by