我知道有一个名为注释可以绘制箭头或双箭头的功能。 但是注释只能情节标准化单元。 例如:
annotation('arrows',[x1 x2],[y1 y2])
在此,[X1,X2]应该比一个更小的比数。
所以,我的问题是我怎么能绘制箭头与真正的价值,而不是一个标准值?
我不知道是否有任何其他的功能,可以处理这个或者是还有什么功能,我可以得到图的坐标值,这样我可以调整的真正价值为标准值。
我知道有一个名为注释可以绘制箭头或双箭头的功能。 但是注释只能情节标准化单元。 例如:
annotation('arrows',[x1 x2],[y1 y2])
在此,[X1,X2]应该比一个更小的比数。
所以,我的问题是我怎么能绘制箭头与真正的价值,而不是一个标准值?
我不知道是否有任何其他的功能,可以处理这个或者是还有什么功能,我可以得到图的坐标值,这样我可以调整的真正价值为标准值。
我刚刚发现了这个方法,因为我不希望有标准化的单位打扰。 使用乳胶解释:
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]')
要使箭头越长,使用较大的字体大小。
优点
缺点
对于标注的定位,MATLAB提供的功能dsxy2figxy
数据空间中的点转换为标准的空间坐标。 但是,不管是什么原因,是不是包含在Matlab的分布函数,并且必须“创造”之首。
下面的线复制到命令行窗口,执行它在编辑器中开启该功能。
edit(fullfile(docroot,'techdoc','creating_plots','examples','dsxy2figxy.m'))
要使用该功能dsxy2figxy
保存在某个地方它在你的MATLAB的搜索路径。
请找到该功能的完整说明dsxy2figxy
在MATLAB的中央: http://www.mathworks.de/help/techdoc/creating_plots/bquk5ia-1.html
即使annotation
使用normalized
作为默认的单位,可以将这些对象到当前的轴(关联gca
设置),并使用数据单元X
和Y
性能。
这里是绘制一个单箭头的一个例子。
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;
对于任何人谁遇到这个话题找绘制箭头“数据空间”,而不是在单位相对于数字和/或轴,我强烈建议arrow.m从文件交换。
如果我没有记错,你需要计算相对于图中的轴的位置。
它应该像:
%% example plot
clf
plot(rand(5,2)*5)
%% get info specific to the axes you plan to plot into
set(gcf,'Units','normalized')
set(gca,'Units','normalized')
ax = axis;
ap = get(gca,'Position')
%% annotation from 1,2 to 3,4
xo = [1,3];
yo = [2,4];
xp = (xo-ax(1))/(ax(2)-ax(1))*ap(3)+ap(1);
yp = (yo-ax(3))/(ax(4)-ax(3))*ap(4)+ap(2);
ah=annotation('arrow',xp,yp,'Color','r');
在原始计算注固定偏移- AP(3),AP(4)的宽度和GCA的高度,而不是角部位置
创建注释对象后,您应该将产权单位 ,以绝对的。 例:
arrowObj = annotation('arrow', [0.1 0.1], [0.5 0.5]);
set(arrowObj, 'Units', 'centimeters');
set(arrowObj, 'Position', [1 1 3 5]);
一种方法是定义在轴线单元的箭头:
Ax=[0 -0.003 0.003 0]; % (Ax,Ay) form an upward pointing arrowhead.
Ay=[0.01 0.0060 0.0060 0.01];
Ax=Ax-mean(Ax); % center it on zero
Ay=Ay-mean(Ay);
然后,在所希望的箭头指数上的曲线VV,计算
x1=vv(in,1); y1=vv(in,2);
x2=vv(in+1,1); y2=vv(in+1,2);
u=x2-x1;
v=y2-y1;
th=-pi/2+atan2(v,u);
R=[cos(th) -sin(th); sin(th) cos(th)]; % Rotation matrix for local slope of vv.
A=R*[Ax;Ay]; % Rotate the arrowhead.
patch(x1+A(1,:),y1+A(2,:),'r','LineWidth',0.01) % plot rotated arrowhead at (x1,y1).
plot(x1+A(1,:),y1+A(2,:),'r','LineWidth',0.01) % Kludge to make boundary red too (I'm sure there is a more elegant way).
工作对我来说,我的具体情况。
您可以使用在(充分证明)的“箭头”组件达芬奇绘制工具箱 (全面披露:我写/卖出工具箱,但箭头是免费的)。
实施例的语法和示例输出如下。
davinci( 'arrow', 'X', [0 10], 'Y', [0 2], <plus-lots-of-options> )