Control decimal places of contour labels
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Day Hong Kim
el 9 de Mayo de 2021
Comentada: Day Hong Kim
el 11 de Mayo de 2021
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.
0 comentarios
Respuesta aceptada
dpb
el 9 de Mayo de 2021
Editada: dpb
el 9 de Mayo de 2021
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...
Más respuestas (0)
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!