Labeling multiple line plots

4 ビュー (過去 30 日間)
Sal Ra
Sal Ra 2020 年 12 月 12 日
コメント済み: Image Analyst 2020 年 12 月 12 日
Hello,
How can I label multiple line plots?
For example, I have this code that generates 20 line plots. What I want is to label each line based on %:
Here is a small portion of sample data:
Percent 5% 10% 20% 30% 40% 50% 60% 70%
Quantity Sale
800 45 90 107 109 110 111 114 116
1300 60 105 132 133 134 136 138 141
1800 35 89 133 141 142 144 145 149
2300 19 70 133 147 148 150 151 155
2900 60 105 132 133 134 136 138 141
3300 35 89 133 141 142 144 145 149
3950 45 90 107 109 110 111 114 116
4700 60 105 132 133 134 136 138 141
I'm ploting:
Plot(Sale, Quantity)
Using legend () for over 30 plot is time consuming. Any better method?
(Later I will need to plot over 80 rows & columns, a better way to identify each line would be helpful)
Thanks in advance!
  2 件のコメント
Image Analyst
Image Analyst 2020 年 12 月 12 日
I don't see how 20 plots come out of that, much less 30. Can you attach whatever code you have so far? And tell us from that matrix, are you plotting rows or columns, and how do you get 20 or 30 instead of 8.
Sal Ra
Sal Ra 2020 年 12 月 12 日
That is just "a small portion of sample data"
Actual data generates 27 plots.

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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 12 月 12 日
編集済み: Cris LaPierre 2020 年 12 月 12 日
I'd do something like this.
Percent = ["5%" "10%" "20%" "30%" "40%" "50%" "60%" "70%"];
Quantity = [800 1300 1800 2300 2900 3300 3950 4700]';
Sale = [45 90 107 109 110 111 114 116
60 105 132 133 134 136 138 141
35 89 133 141 142 144 145 149
19 70 133 147 148 150 151 155
60 105 132 133 134 136 138 141
35 89 133 141 142 144 145 149
45 90 107 109 110 111 114 116
60 105 132 133 134 136 138 141];
plot(Quantity,Sale)
legend(Percent,'Location','EastOutside')
  2 件のコメント
Sal Ra
Sal Ra 2020 年 12 月 12 日
Thanks.
So I guess have to use legend.
Image Analyst
Image Analyst 2020 年 12 月 12 日
Why do you say using legend() is time consuming? Can you use tic and toc and tell us exactly how long the legend call takes? It should be virtually instantaneous.

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

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by