pet*_*r e 5 matlab plot matlab-figure
代码
figure
scatter([1,2,3],[1,2,3]);
ax = gca;
ax.YDir = 'reverse'
ah = annotation('arrow','position',[ 2.5 2.5 -1 -1]);
set(ah,'parent',ax);
Run Code Online (Sandbox Code Playgroud)
给出错误的矢量头对齐:
有什么想法如何解决这个问题吗?
处理该问题的一种方法是使用两个单独的注释创建箭头和线条:
figure
scatter([1,2,3],[1,2,3]);
ax = gca;
ax.YDir = 'reverse'
%Define the variable
xac = 2.5; %x arrow coordinate
yac = 2.5; %y arrow coordinate
xas = -1; %x arrow shift
yas = -1; %y arrow shift
if get(ax,'Ydir') == 'reverse':
%Create the arrow
ah1 = annotation('arrow','position',[ xac yac+2*yas xas -yas],'linestyle','none');
set(ah1,'parent',ax);
%Create the line
ah2 = annotation('arrow','position',[ xac yac xas yas],'headstyle','none');
set(ah2,'parent',ax);
else:
ah = annotation('arrow','position',[ xac yac xas yas]);
set(ah,'parent',ax);
end
Run Code Online (Sandbox Code Playgroud)
箭头坐标现在所在的位置xac yac+2*yas xas -yas,
结果: