How to label different lines in a loglog plot

24 visualizzazioni (ultimi 30 giorni)
Cameron Park
Cameron Park il 20 Lug 2017
Risposto: Chad Greene il 20 Lug 2017
I have a bunch of different loglog plots of different power spectral density functions on the same graph (using hold on function) and I am trying to add labels to be able to differentiate the different lines. Does anyone know how to do this? I have many different loglog(psd(A)) for example, and would like to have a legend to be able to tell which color corresponds to which letter (ie blue line is A). New to matlab so would appreciate any help! Thanks!

Risposte (2)

Star Strider
Star Strider il 20 Lug 2017
See the documentation on the legend (link) function.

Chad Greene
Chad Greene il 20 Lug 2017
Here's two ways. You can use a legend or you can use text to manually place a label where you want it:
x = logspace(-1,2);
y = exp(x);
loglog(x,y,'bs-')
y2 = exp(x.^1.2);
hold on
loglog(x,y2,'r')
legend('y1','y2','location','northwest')
text(x(45),y(45),'y1','color','b','vert','top')
text(x(45),y2(45),'y2','color','r','horiz','right')

Community Treasure Hunt

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

Start Hunting!

Translated by