Label contour plot elevation marking with text

조회 수: 38 (최근 30일)
Liam C
Liam C 2019년 7월 31일
답변: dpb 2019년 7월 31일
I was wondering if it is possible to label contour plot elevation lines with text in MATLAB.
My current plot has elervation markings eg. 0.4. I want to mark the lines with n = 0.4 rathe than just 0.4.
Thanks,
Liam

채택된 답변

dpb
dpb 2019년 7월 31일
By using clabel instead, yes...but takes some munging-on there, even. Using the example from countour as starting point--
x = -2:0.2:2;
y = -2:0.2:3;
[X,Y] = meshgrid(x,y);
Z = X.*exp(-X.^2-Y.^2);
figure
[C,h]=contour(X,Y,Z,'ShowText','off');
hT=clabel(C,0.4);
hT(2).String=['n = ' hT(2).String];
hT(1).Color='w';
results in
untitled.jpg
It'll take quite a bit of cleanup from here, but it is at least possible.
The problem ran into w/ R2017b w/ clabel is that it won't return the text object line handles for many combinations of inputs and the only ones I found that would include the '+' and upright text -- not possible with the default inline text.
To do that and then find the handles would take "handle-diving" into the hidden properties not exposed by default to find and modify those text() objects appropriately.
Not a task for the faint-hearted and it best be really, really important, probably!
Not bad for an enhancement request, though, like so much of HG2, there are always things that could be done that TMW just chose not to let the user be able to get at easily.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by