Control decimal places of contour labels

조회 수: 11 (최근 30일)
Day Hong Kim
Day Hong Kim 2021년 5월 9일
댓글: Day Hong Kim 2021년 5월 11일
Hello all, hope you having a great day. I am trying to figure out how to control decimal places of contour labels. What I would like to do is that all the values have 1 decimal place. However, when the value is an integer, it does not show its decimal. For example, if the value is 10.0, the contour label only shows 10. If you have any idea and share it for me, I would be really thankful.

채택된 답변

dpb
dpb 2021년 5월 9일
편집: dpb 2021년 5월 9일
Yet another case where TMW (The MathWorks) has been too aggressive in hiding stuff that clearly users would want to and should be able to control...there is no 'format' or 'precision' property for contour labels exposed; in fact, there isn't one even in the hidden properties of the contour object.
There is an array of text objects that are the text written that can be munged on with some effort...
...
[~,hC]=contour(X,Y,Z,'ShowText','on'); % create contour plot from example doc, save handle
hTxt=hC.TextPrims; % array of text contour objects handles
isNoDec=find(~arrayfun(@(h)contains(h.String,'.'),hTxt)); % find those missing decimal
arrayfun(@(h)set(h,'String',strcat(h.String,'.0')),hTxt(isNoDec)) % and add a trailing ".0"
"Oh, the tangled web Handle Graphics weaves...when the vendor doth hide the leaves."
One needs Yair Altman's UNDCOUMENTED File Exchange submission to easily probe inside the hidden properties to be able find these goodies.
The above example with a tile layout produced the following figure--note the center line at zero on the lower subplot is "0.0" rather than "0" in the upper...
It's truly remarkable what effort is wasted having to clean up things for such inconsistencies. I've ranted about the same issue regarding the default formatting for the standard 0-1 axes that is the result of the defaultl '%g' format string -- at least it is fixable and one can change the default; these like this buried in the bowels and hidden are beyond ... one either just accepts it as "the way things are" or spends an hour or more digging around...
  댓글 수: 1
Day Hong Kim
Day Hong Kim 2021년 5월 11일
Thank you for the information. It really helped me a lot. As you mentioned above, I agree that it is frustrating when just a small thing such as changing decimal places bothers you. Hope MATLAB updates for more user-friendly.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by