Labeling multiple line plots

4 visualizzazioni (ultimi 30 giorni)
Sal Ra
Sal Ra il 12 Dic 2020
Commentato: Image Analyst il 12 Dic 2020
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 Commenti
Image Analyst
Image Analyst il 12 Dic 2020
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 il 12 Dic 2020
That is just "a small portion of sample data"
Actual data generates 27 plots.

Accedi per commentare.

Risposte (1)

Cris LaPierre
Cris LaPierre il 12 Dic 2020
Modificato: Cris LaPierre il 12 Dic 2020
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 Commenti
Sal Ra
Sal Ra il 12 Dic 2020
Thanks.
So I guess have to use legend.
Image Analyst
Image Analyst il 12 Dic 2020
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.

Accedi per commentare.

Tag

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by