Annotation Displays in the Wrong Location

7 ビュー (過去 30 日間)
DH
DH 2023 年 4 月 17 日
コメント済み: DH 2023 年 4 月 20 日
Using Matlab 2020b, I am trying to dislplay an annotation with code like the block shown below. The functions x_to_norm_v2 and y_to_norm_v2 are from the Mathworks website, here:
The first figure below is how it looks when I run the code. The second figure is how I want it to display. I found that if I set a breakpoint right after the first line of code below (the line that defines fg1 as a figure), it displays properly. How can I fix this so it displays properly without having to set a breakpoint?
fg1 = figure('NumberTitle', 'off', 'WindowStyle', 'docked');
numPltRws = 2;
numPltCls = 2;
pltndx1 = 0;
chrt = tiledlayout(numPltRws, numPltCls);
pltndx1 = pltndx1 + 1;
plt1(pltndx1) = nexttile;
loglog(1, 1, 'ok');
[x_norm] = x_to_norm_v2(3,1);
[y_norm] = y_to_norm_v2(1,1);
annotation('textarrow', [x_norm], [y_norm], 'String', 'Annotation');
grid
The output looks like:
  5 件のコメント
DH
DH 2023 年 4 月 17 日
Thank you - that works too. And it eliminates the delay, which is good. I will use that function. I was not aware of the drawnow() function. Thank you for your help.
DH
DH 2023 年 4 月 20 日
Because the above response was given as a comment, and not an answer, there is no "Accept this answer" button to click on, but this is the response that best solved my problem at this time. Thank you.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 4 月 17 日
What is happening is that by default the coordinates used for annotation() are normalized to the figure.
The call to figure() will always involve a flush of the graphics queue, but you then create tiled layouts and loglog(), and the positions of those graphics objects will not be finalized until the next time the graphics queue is flushed.
Unfortunately, annotation does not provide any way to specify data coordinates; https://www.mathworks.com/help/matlab/ref/matlab.graphics.shape.textarrow-properties.html#buchvf6-1_sep_shared-Units or even to use normalized units relative to the axes. The closest you could get would be to created a uipanel around each axes, as you can normalize to a container such as uipanel.
Or you can look in the File Exchange, as there are some contributions there that can assist in providing annotations in data coordinates. The better of the contributions hook into the figure or axes size change callbacks and re-calculate the coordinates as needed.

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by