Control decimal places of contour labels

10 次查看(过去 30 天)
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 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by