Annotation Displays in the Wrong Location
7 次查看(过去 30 天)
显示 更早的评论
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:
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!