Labelling plot lines akin to contour labels

Dear Matlab Community,
I would like to annotate a simple 2D plot line in a similar way to how contour levels are labelled in contour. That is, the line appears broken with some label text centred on the line. The idea here is that one could label multiple plots neatly, without the use of a legend.
Does anybody know a way to do this? Obviously, one could use annotation, but setting this up in a generic way could prove to be difficult (at least for me).
Cheers, Steven.

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 8월 17일

0 개 추천

I don't know any way directly. All I can suggest is to look at contour.m to see if you can make you own. Share with us if you do find a way.
Find this interesting note in contour.m. Might it give you some leads? The function is in clabel.m
% Thanks to R. Pawlowicz (IOS) rich@ios.bc.ca for 'contours.m' and
% 'clabel.m/inline_labels' so that contour now works with parametric
% surfaces and inline contour labels.
t=0:0.1:7;
y=sin(t);
z=cos(t);
plot(t,t,'r',t,y,'g',t,z,'b',t,y+z,'k');
Strings={'line','sin','cos','sin+cos'};
LabelLine(gca,Strings);
function LabelLine(h_axes,LabelStrings)
h_line=findobj(h_axes,'type','line');
n=length(h_line);
for k=1:n;
XData=get(h_line(k),'XData');
YData=get(h_line(k),'YData');
Ind=round(length(XData)/2);
text(XData(Ind),YData(Ind),LabelStrings{n-k+1});
end

댓글 수: 4

Steven White
Steven White 2011년 8월 17일
I have had a look at the clabel.m code. Unfortunately, this is beyond my Matlab skill set and so I am unable to alter it into something I can use.
Steven.
Fangjun Jiang
Fangjun Jiang 2011년 8월 18일
I think the technique is to use text(). I can build a rudimentary one. Not really a generic function, but don't want to get nothing out after reading the clabel.m code.
Steven White
Steven White 2011년 8월 19일
Thanks very much. This is more or less what I am after. I can play with the text properties to change colours etc.
Many thanks,
Steven.
Sandeep K
Sandeep K 2018년 2월 22일
Hello,
Is there any other way of doing this plotting using R2017?
Thank you
Sandeep

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

질문:

2011년 8월 17일

댓글:

2018년 2월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by