Labelling mulitple traces on plot

Hi,
How would you go about automatically labeling each trace on a plot for the case where the values are automatically generated in a for loop
from this
to this
The labels either sitting on top of each trace or adjacent outside the plot preferably with transparent background.
my code:
for nn = 1:Kappan
cc = jet(Kappan);
figure(1)
loglog(dratio,G(nn,:),'.-','color',cc(nn,:))
grid on
xlabel('Length / Diameter')
ylabel('Gain')
legend('boxoff'),legend(c,'location','NorthWest')
hold on
end
hold off
Thank You,
Joe

3 Comments

What is your "c" variable that you are passing as the first argument to legend() ?
Hi Thanks for the replies. c variable is to color each trace code below
c={}; for i=1:length(Kappa) c{end+1}=num2str(Kappa(i)); end
for nn = 1:Kappan cc = jet(Kappan); figure(1) loglog(dratio,G(nn,:),'.-','color',cc(nn,:)) grid on xlabel('Length / Diameter') ylabel('Gain') legend('boxoff'),legend(c,'location','NorthWest') hold on end hold off
% set(gcf, 'PaperPositionMode', 'auto'); saveas(gcf, 'test2', 'pdf') %Save figure export_fig('C:\Users\Joseph\Documents\Geophysics\PhD\Matlab', '-pdf','-painters');
I adjusted my code accordingly.

Sign in to comment.

 Accepted Answer

Walter Roberson
Walter Roberson on 18 Mar 2013
Edited: Walter Roberson on 18 Mar 2013
figure(1)
for nn = 1:Kappan
loglog(dratio, G(nn,:), 'kd', 'LineStyle', 'none');
if nn == 1
grid on
xlabel('Length / Diameter')
ylabel('Gain')
hold on
end
text(dratio(end), G(nn,end), str2num(Kappa(nn)), 'HitTest', 'off', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'bottom')
end
hold off
We need more information in order to generate the "wait" line and the infinity trace.

6 Comments

Much appreciated.
The code I gave above should do to replace everything from "c={};" downward.
However, the sample figure you desire has a solid "wait" line shown, and to plot that we will need an equation, and we need to know which dratio values to plot it at. In the diagram you showed, the last 6 markers were not included in the "wait" line, except for the 200 and infinity case which excludes fewer markers (unless there is simply a "ylim" in effect that cuts some of them out of the figure.)
Sorry If I haven't mentioned this before I am just using equation (29)and ignoring the wait trace. If I put in xlim and ylim the text labels for Kappa dissapear. Therefore I would like to resize my plot to fit nicely for different Kappa values. How do you plot if a value Kappa is infinity?
Where I used dratio(end), G(nn,end) you could substitute something like dratio(end-6), G(nn,end-6) to move the label further left along.
If you were to add infinity to the Kappa list, then "infinity" or perhaps "inf" would be used as the label. When you had the equation up, I had the impression you would be likely to get NaN for the outputs when the kappa was infinity, though (I did not try it myself.)
Yes, that's correct. Nan for the output of Gain if Kappa = Inf. So I guess I'll put an arbitrary large number for example 10^10 as Inf. And then how would you replace 10^10 on the text label with Inf?
if nn == Kappan
Kstr = 'inf';
else
Kstr = str2num(Kappa(nn));
end
text(dratio(end), G(nn,end), Kstr, 'HitTest', 'off', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'bottom')

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!