MATLAB Answers

0

How do I change the labels values under contour plot (CONTOUR and CLABEL)?

Asked by Ricko Lase on 13 Aug 2018
Latest activity Commented on by Ricko Lase on 16 Aug 2018
I have a simulation that produces range of numbers which I plotted into Contour plot. The problem is, these values are not linear in respect to X or Y axis and visually it is better to plot them as decibel (dB). See below
Related Code:
[C,h] = contour(XPOS_VECT,YPOS_VECT,Values,50,'ShowText','on');
set(gca,'Clim',[150 210]);
While it is easier to see visually, non technical people (my target audience of this plot) might misunderstand the values as they are described in dB rather than linear. Therefore, I would like my contour plot to have pattern in dB progression (as shown in the figure above) while the label shows linear number associated with each dB number. Can someone provide any insight or help for this? Thanks beforehand

  0 Comments

Sign in to comment.

Products


Release

R2018a

1 Answer

Answer by jonas
on 13 Aug 2018
Edited by jonas
on 16 Aug 2018
 Accepted Answer

Turns out if you do not pass the contour handle to clabel, then clabel outputs the labels, which you can easily change. If you instead add the contour handle, then the labels are stored in the contour handle's hidden property 'TextPrism'.
Here's an example where the labels are increased by a factor of two using the hidden property:
[C,hContour]=contourf(peaks)
clabel(C,hContour)
drawnow
labels=hContour.TextPrims
for idx = 1 : numel(labels)
LabelValue=str2num(labels(idx).String);
NewValue=LabelValue*2;
hContour.TextPrims(idx).String=num2str(NewValue)
end

  4 Comments

Show 1 older comment
Added some code using the undocumented features (thanks Walter). It puts the labels inside the contour lines per default.
EDIT: I accidentally removed the first approach, however the new one is better anyway!
Thanks Jonas and Walter, your combined responses managed to solve my problems. Much appreciated

Sign in to comment.