Labeling multiple line plots
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Image Analyst
el 12 de Dic. de 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.
Respuestas (1)
Cris LaPierre
el 12 de Dic. de 2020
Editada: Cris LaPierre
el 12 de Dic. de 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 comentarios
Image Analyst
el 12 de Dic. de 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.
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
