Labelling multiple plots of the same color with a single legend label.
18 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
I am trying to plot multiple sets of data on a single plot within a while statement. I have two sets of data I plot for each "while value" and I want those sets to be the same color when I plot them which I was able to do but I also want to label them as the same thing in a legend without having the labelling repeat. Currently the way I have formatted the code, the label repeats for both sets of data as shown in my code below. If someone could help out with this that would be great, thank you!
0 件のコメント
採用された回答
その他の回答 (1 件)
Sulaymon Eshkabilov
2023 年 1 月 6 日
In your exerise, there are a coupole of different ways to do that.
(1) An easier one is to combine your data and plot them once the simulation is complete.
...
ii=0;
N = 11;
while ii <N
x(ii)=...
y(ii) = ...
ii = ii+1;
end
plot(x, y, 'DisplayName', 'x vs. y')
legend show
...
(2) Skip the legend in the second round, setting legend 'off', e.g.:
...
while ii<N
plot(x(ii), y(ii), 'DisplayName', 'x vs. y')
hold on
h = plot(x(ii+1), y(ii+1), 'DisplayName', 'x+1 vs. y+1');
h.Annotation.LegendInformation.IconDisplayStyle = 'off';
ii=ii+1;
end
legend show
...
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!