How to precisely place textarrow?
古いコメントを表示
Inside a plot, I want to place several textarrows to mark specific events on the timeline. However, their placement is not very precise. Consider this MWE:
clc; clearvars
startEndDtStr = ["01.08.2022 06:00:00", "11.08.2022 06:00:00"];
startEndDateTime = datetime(startEndDtStr);
daysTotal = days(diff(startEndDateTime));
dtVector = startEndDateTime(1):hours(1):startEndDateTime(2);
%% Create plot
fh1 = figure('Position', [180 112 1150 650]);
plot(dtVector, sinpi(days(dtVector - startEndDateTime(1)))+1, 'LineWidth',1.5);
hold on; grid on
xArrow1 = days(datetime(2022,8,6,6,0,0) - startEndDateTime(1))/daysTotal;
annotation('textarrow', [xArrow1+.03 xArrow1], [1.7 1.0]./2, 'String',"Start Event", 'FontSize',14);
xlim(startEndDateTime);
xticks(startEndDateTime(1):days(2):startEndDateTime(2));
set(gca, 'FontSize',16);
% exportgraphics(fh1,'textArrowPlacement.png', 'Resolution',300)
Which produces this plot:

As you can see, the tip of the arrow does not end at [0.5, 0.5] in relative coordinates, or [August 06/2022/06:00, 1] in absolute coordinates. I suppose it has something to do with the plot area.
What would be the code to get it there?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!