Error in datatips in plot

32 Ansichten (letzte 30 Tage)
Sebastian
Sebastian am 26 Nov. 2025
Bearbeitet: dpb am 28 Nov. 2025 um 14:33
I run the following command
plot([1 2],8388608*[1 1])
However when i put a marker on the two data points in the plot the y value is incorrect
Same for x value
plot(8388608*[1 1]+[0 1],8388608*[1 1],'r*')

Akzeptierte Antwort

dpb
dpb am 26 Nov. 2025 um 17:47
Bearbeitet: dpb am 28 Nov. 2025 um 14:33
This is a builtin feature of the way the datatips work...by default there seems to be a rounding to 6 significant digits with the 'auto' format setting.
hL=plot([1 2],8388608*[1 1],'*-'); % the example large integer plotted
xlim(xlim+0.1*[-1 1]) % stretch x so points aren't identically on boundaries
hAx=gca;
hAx.YAxis.TickLabelFormat='%.1f'; % clean up y labels
hAx.YAxis.Exponent=0;
% the above is all just preliminaries; the issue about datatip display follows...
hL.DataTipTemplate
ans =
DataTipTemplate with properties: DataTipRows: [2×1 matlab.graphics.datatip.DataTipTextRow] Interpreter: 'tex' FontSize: 10 FontAngle: 'normal' FontName: 'Helvetica'
hL.DataTipTemplate.DataTipRows
ans = 2×1 DataTipTextRow array with properties:
Label Value Format
hL.DataTipTemplate.DataTipRows.Format
ans = 'auto'
ans = 'auto'
[hL.DataTipTemplate.DataTipRows.Format]=deal("%d","%d");
will work for the present integer values; can be adjusted as needed for specific data sets.
hL.DataTipTemplate.DataTipRows.Format
ans = '%d'
ans = '%d'
Since the property is a member of the line it can't be set until the line is drawn unless one makes a change in the root property of the graphics root. That's doable either at the global level or for a specific figure or session depending upon needs.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by