Hello everyone! I am required to annotate multiple line plots with the numbers as can be seen in the figure. I have put the numbers between the lines using 'plot edit toolbar', but I wish to do it in the code. I have tried many commands like annotation, text, ds2nfu, but all commands requires x and y coordinates for the location of annotation. I just need a number, which is unique to that particular line plot to be printed in the manner as can be seen in the figure. Is there any way wherein I can insert these numbers to the respective plots without extracting the location data? Because, I wont be aware of the x and y most of the times! Your inputs are welcome! Thank you in advance!

 Akzeptierte Antwort

Thorsten
Thorsten am 11 Nov. 2015
Bearbeitet: Thorsten am 11 Nov. 2015

0 Stimmen

Well, you are aware of the x and y pos, because you can plot the line. You can do the following
x = 1:10+randi(10);
y = [rand*x; rand*x; rand*x; rand*x];
plot(x,y')
ind = round([0.5 0.55 0.6 0.65]*numel(x)); % specify the x positions
labels = {'36' '40' '44' '42'}; % the labels of the lines
for i =1:numel(ind)
text(x(ind(i)), y(i, ind(i)), labels{i})
end

5 Kommentare

Karthik Brs
Karthik Brs am 11 Nov. 2015
Hello Thorsten, Thank you for your time! I don't know the x and y data in the sense, I may get other text files, with different x and y data. So, I want to write a code which is general and should work on any range of values (irrespective of x and y coordinate data) . I want the annotations for the line and not for the coordinates! Hope you understood my requirement!
Thorsten
Thorsten am 11 Nov. 2015
Bearbeitet: Thorsten am 11 Nov. 2015
You could specify the xpos as
xpos = round([0.5 0.6 0.7]*numel(x));
Then the labels are plotted at 50%, 60% and 70% the length of the x coordinates, at the corresponding y values of the lines. I modified my example for random x and y to show that it works. Is this what you need?
Mmmm.. Let me attach my my workspace variable here. Even after I ran the code with your modified input, the was able to get the numbers on to the graphs, but they not in the visible location. The code which I am using is given below,
%%Campbell diagram
t1 = cell2mat(tempLw(1)); t2 = cell2mat(tempLw(2));
t3 = cell2mat(tempLw(3)); t4 = cell2mat(tempLw(4));
figure(50);
wf = waterfall([a1 a1 a1 a1]',[F1 F2 F3 F4]',[t1 t2 t3 t4]');
view([0 90]); %Sets the default viewport to X-Y plane
xlabel('RPM','FontSize',12,'Fontweight','bold');
ylabel('Frequency','FontSize',12,'Fontweight','bold');
title('Campbell diagram','FontSize',16,'Fontweight','bold');
cb = colorbar('eastoutside');
set(get(cb,'title'),'string','Schalleistung in dB');
set(wf,'Linewidth',4);
hold on
grid on
plot(a1,F1,'k',a1,F2,'k',a1,F3,'k',a1,F4,'k','Linewidth',0.001);
Use
x = a1;
y = [F1 F2 F3 F4]';
and run the modified code above, starting from the fifth line
ind = ....
Karthik Brs
Karthik Brs am 11 Nov. 2015
Works like a charm! Thanks a ton!! :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by