datatip gives same x value for different samples

Here is a simplified example of my problem. How can I get tooltips to show X 500000, X 500001, X 500002, etc.? Instead it shows X 500000 for all of these points. When the number of points is large enough, tooltips does not give correct integer sample number.
x = 1:1e6; % sample number
y = (-1).^x;
plot( y,'.' ); ylim( [-1.5 1.5]); xlim([500000 500020]);
title('R2020a: Tooltip shows X 500000 for all the points')

 採用された回答

Mario Malic
Mario Malic 2022 年 12 月 6 日
編集済み: Mario Malic 2022 年 12 月 6 日

0 投票

Hey Paul,
I am using the R2021b and I see the datatips properly, but you can play with the last two lines to get your desired output.
x = 1:1e6; % sample number
y = (-1).^x;
lineHandle = plot( y,'.' ); ylim( [-1.5 1.5]); xlim([500000 500020]);
title('R2020a: Tooltip shows X 500000 for all the points')
dt = datatip(lineHandle, 500010, 1);
% You can play with format specification to get the desired output
lineHandle.DataTipTemplate.DataTipRows(1).Format = '%6d';
lineHandle.DataTipTemplate.DataTipRows(2).Format = '%6d';
% lineHandle.DataTipTemplate.DataTipRows.Format is a comma separated list,
% I never remember how to assign to it

4 件のコメント

Paul Hoffrichter
Paul Hoffrichter 2022 年 12 月 6 日
In R2020a, got error:
Unrecognized method, property, or field. 'Format' for class 'matlab.graphics.datatip.DataTipTemplate'.
Error in Tooltip (line 5)
lineHandle.DataTipTemplate.Format
I don't see 'Format' in this documentation:
Maybe this is a recent undocumented feature.
Paul Hoffrichter
Paul Hoffrichter 2022 年 12 月 6 日
With your edited answer, I now get:
Unrecognized method, property, or field. 'DataTipRows' for class 'matlab.graphics.datatip.DataTipTemplate'.
Paul Hoffrichter
Paul Hoffrichter 2022 年 12 月 6 日
Works. Thanks for digging that out of R2020a docs.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by