如何在Matlab中用数据坐标绘制箭头?

dat*_*tcn 23 matlab plot annotations figure

我知道有一个名为annotation的函数可以绘制箭头或双箭头.但是注释只能以标准化单位绘制.例如:

annotation('arrows',[x1 x2],[y1 y2])
Run Code Online (Sandbox Code Playgroud)

这里,[x1,x2]应该是小于1的比率数.

所以,我的问题是如何绘制具有真值而不是标准化值的箭头?

我想知道是否有任何其他功能可以接近这个或者是否有任何函数我可以得到图的轴值,以便我可以将真值调整为标准化值.

H.M*_*ter 12

对于注释的定位,Matlab提供了dsxy2figxy将数据空间点转换为标准化空间坐标的功能.但是,无论出于何种原因,该功能都不包含在Matlab发行版中,必须先"创建".

将以下行复制到命令窗口并执行它以在编辑器中打开该功能.

edit(fullfile(docroot,'techdoc','creating_plots','examples','dsxy2figxy.m'))
Run Code Online (Sandbox Code Playgroud)

要使用该功能,dsxy2figxy请将其保存在matlab搜索路径中的某个位置.

dsxy2figxy在matlab-central上找到该功能的完整说明:http://www.mathworks.de/help/techdoc/creating_plots/bquk5ia-1.html


mar*_*sei 10

即使annotation使用normalized作为默认的单位,可以将这些对象到当前的轴(副gca),并使用数据单位设置XY属性.

以下是绘制单箭头的示例.

plot(1:10);
ha = annotation('arrow');  % store the arrow information in ha
ha.Parent = gca;           % associate the arrow the the current axes
ha.X = [5.5 5.5];          % the location in data units
ha.Y = [2 8];   

ha.LineWidth  = 3;          % make the arrow bolder for the picture
ha.HeadWidth  = 30;
ha.HeadLength = 30;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


tmp*_*rce 8

对于遇到这个主题的人来说,想要在"数据空间"中绘制箭头而不是相对于图形和/或轴的单位,我强烈推荐来自文件交换的arrow.m.


Dav*_*d_G 5

我刚刚发现了这种方法,因为我不想打扰标准化单位.使用乳胶解释器:

figure
plot([1:5],[1:5]*3,'.-')
%// Say I want to put an arrow pointing to the location, [3 9]    
text(2.94,8.3,'\uparrow','fontsize',20)
text(2.8,7.8,'point [3,9]')
Run Code Online (Sandbox Code Playgroud)

要使箭头更长,请使用更大的字体大小.

优点

  • 比使用标准化单位更容易,更快速,更快捷
  • 不需要安装任何功能(对我们懒惰的人有好处..)
  • 利用LaTeX解释器,有一系列箭头(上,下,左,右和其他角度)(见符号列表)

缺点

  • 绝对需要试验和错误/调整以获得箭头相对于POI的正确位置.
  • 对箭头长度的控制有限
  • 解释器(boo)无法理解某些乳胶命令.