Increasing datatip display precision (MATLAB 2019a)

355 ビュー (過去 30 日間)
Ni Made Ayu Sinta Dewi
Ni Made Ayu Sinta Dewi 2021 年 7 月 4 日
コメント済み: Sanika Baste 2023 年 5 月 2 日
Help! I want to increase the datatip display precision. How do I do this? Is it possible to do this automatically for all datatips?
If that is not possible, is there a way to at least make the datatip display the same level of precision (show the same number of digits after the decimal point)? In my case (photo attached), the datatip is not showing zeros. I want these datatips to show 0,25220 and 0,80351.
Thank you in advance.
  3 件のコメント
Peter O
Peter O 2021 年 7 月 5 日
Here's the walkthrough for the (older) programmatic way to do it:
First, you create a data cursor mode object for the figure and override the default callback function for its update. You can then give it a text string back for custom display. Return as a set of cell strings to get multiple rows.
% Script
plot(1:10,cos(1:10))
dcm = datacursormode(gcf);
dcm.Enable='on';
dcm.UpdateFcn = @threeRows;
% Separate File: threeRows.m
function txt = threeRows(~, info)
x = info.Position(1);
y = info.Position(2);
txt = [{num2str(x);num2str(y);num2str(x^2+y^2)}];
end
In later versions you can use the datatip textrow for formatting control: https://www.mathworks.com/help/matlab/ref/matlab.graphics.datatip.datatiptextrow.html
Ni Made Ayu Sinta Dewi
Ni Made Ayu Sinta Dewi 2021 年 7 月 6 日
Thank you so much!

サインインしてコメントする。

採用された回答

Peter O
Peter O 2021 年 7 月 4 日
Quick and dirty way (works in 2021, I think should still work in 2019):
  1. Create a data tip and right-click on it. Edit content and style.
  2. You'll see a popover that has "DataTipRows". Click that and then click the field you want to adjust. Format is set to AUTO.
  3. Type in the precision you want into that field using MATLAB's standard nomenclature, so for 5 spaces and 3 decimal points as a float: %5.3f
  4. This will affect the datatips globally on a plot. If you set the decimal precision then the requisite number of zeros should appear.
There's also a programmatic way, which is the backdoor to that and just involves a few function calls. Let me know if you need that and I can dig it up. I've used it in the past to add things like a third row to display an index or identifier of a data point (helpful for image processing and pareto plot point identification)
  2 件のコメント
Ni Made Ayu Sinta Dewi
Ni Made Ayu Sinta Dewi 2021 年 7 月 4 日
This worked, but I would like to learn the function call that you mentioned as well. Thank you in advance!
Sanika Baste
Sanika Baste 2023 年 5 月 2 日
Super helpful... thanks :D

サインインしてコメントする。

その他の回答 (2 件)

Mike
Mike 2021 年 9 月 29 日
Peter O's approach can be implemented programatically by modifying the DataTipTemplate.
For example:
p = plot(x,y);
p.DataTipTemplate.DataTipRows(1).Format = '%g'; % x
p.DataTipTemplate.DataTipRows(2).Format = '%g'; % y

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 7 月 4 日
That would be easier to round up your plotted data using round(data, Ndd), e.g.:
X=round(x, 5); Y=round(Y,5); plot...
% Then your datatip shows 5 cdd

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by