gpt4 book ai didi

matlab - matlab图中的注释

转载 作者:太空宇宙 更新时间:2023-11-03 19:49:48 25 4
gpt4 key购买 nike

我只是想知道如何在 matlab 绘图中添加注释?这是我的代码:

plot(x,y);  
annotation('textarrow',[x, x+0.05],[y,y+0.05],'String','my point','FontSize',14);

但是箭头指向了错误的地方。我该如何解决?还有更好的注释图的想法吗?

谢谢和问候!


编辑:

刚刚从帮助文档中看到:

annotation('line',x,y) creates a line annotation object that extends from the point defined by x(1),y(1) to the point defined by x(2),y(2), specified in normalized figure units.

在我的代码中,我希望箭头指向由 plot() 绘制的点 (x,y),但注释将 x 和 y 的值解释为标准化图形单位。所以我认为这就是导致问题的原因。如何为注释指定正确的坐标?

最佳答案

首先,您需要以标准化图形单位找到轴的位置。幸运的是,它们默认设置为“标准化”。

axPos = get(gca,'Position'); %# gca gets the handle to the current axes

axPos 是[xMin,yMin,xExtent,yExtent]

然后,您得到限制,即轴的最小值和最大值。

xMinMax = xlim;
yMinMax = ylim;

最后,您可以根据绘图 x 和 y 计算注释 x 和 y。

xAnnotation = axPos(1) + ((xPlot - xMinMax(1))/(xMinMax(2)-xMinMax(1))) * axPos(3);
yAnnotation = axPos(2) + ((yPlot - yMinMax(1))/(yMinMax(2)-yMinMax(1))) * axPos(4);

使用 xAnnotation 和 yAnnotation 作为注释的 x 和 y 坐标。

关于matlab - matlab图中的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2603612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com