Spooky Graphed Data?

Data tip doesn't match Yaxis or actual data. Actual data is 1073741824.
Can anyone explain this?

回答(2 个)

dpb
dpb 2025-10-31

0 个投票

Longstanding behavior -- the datatip values are rounded to some (as far as I know an unspecified) number of significant digits; probably for cleanliness of display considerations.
a=plot(1073741820:1073741829);
datatip(a);
c=a.DataTipTemplate;
c.DataTipRows(2).Format
ans = 'auto'
c.DataTipRows(2).Format='%d';

5 个评论

I don't know if one can change the template for the axis callback datatip, though???
a=plot(1073741820:1073741829);
%datatip(a);
c=a.DataTipTemplate
c =
DataTipTemplate with properties: DataTipRows: [2×1 matlab.graphics.datatip.DataTipTextRow] Interpreter: 'tex' FontSize: 10 FontAngle: 'normal' FontName: 'Helvetica'
And Lo! and behold, the datatip is another of those undocumented and hidden line properties Mathworks doesn't tell us anything about other than the creation programmatically with the datatip function which neglects to mention or link to anything about the default interactive behavior.
Thanks, @Fangjun Jiang, your response made me go try it without creating one and discovered it lurks there all the time.
The default format is 'auto' which undoubtedly transforms into '%g' internally and so
format longg
1073741824
ans =
1073741824
format shortg
1073741824
ans =
1.0737e+09
fprintf('%g\n',1073741824)
1.07374e+09
fprintf('%.6g\n',1073741824)
1.07374e+09
fprintf('%d\n',round(1073741824,-4))
1073740000
So, in fact, it does appear that for some size of values, 'auto' does resort to rounding to a given number of significant digits. Why would seem uncertain.
"... it does appear that for some size of values, 'auto' does resort to rounding ..."
Maybe an enhancement request could be to only round if non-integer value?
Of course, once one knows that one can actually change the interactive behavior, then it's controllable to set the format. I suppose one could also set this as one of the groot conditions either globally or for a given set of figures.
Thank you @dpb for digging it up. I tried and saw the "auto" format and then searched for the other format. That is all I did.
The real contribution was yours to make me curious about whether the interactive callback used the same ptopertiy and then that led to the discovery it is an undocumented and hidden(*) property of every line object.
(*) The actual property .DataTipRows is hidden such that even <Yair Altman's near magical GETUNDOCUMENTED function> doesn't find it which; having never seen it before, had led me to the erroneeous conclusion long ago that it was implemented as an internal callback from the axes and the two weren't really connected at all. Certainly the documentation doesn't provide any hint.
>> HL=plot(rand(10,1); % generate line handle to poke at...
>> U=getundocumented(HL)
U =
struct with fields:
ALimInclude: on
ALimIncludeMode: 'auto'
ALimInclude_I: on
AlignVertexCentersMode: 'auto'
...
CLimInclude_I: on
ChildrenMode: 'auto'
Children_I: [0×0 GraphicsPlaceholder]
ClippingMode: 'auto'
Clipping_I: on
Color_I: [0 0.447 0.741]
Copyable: 1
CreateFcnMode: 'auto'
CreateFcn_I: ''
CreateFcn_IS: '???'
DataTipTemplate_IS: [0×0 GraphicsPlaceholder]
DatetimeTickFormat: ''
DefaultPropMap_Internal: [0×0 struct]
...
>>
reveals only an empty graphics object placeholder; no hint that the actual set of properties are extant and addressable if one does stumble onto the fact they do belong to the lines on the axes.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Environment and Settings 的更多信息

产品

版本

R2024b

标签

提问:

2025-10-31

编辑:

dpb
2025-11-4

Community Treasure Hunt

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

Start Hunting!

Translated by