gpt4 book ai didi

matlab - 如果 y 方向设置为 'reverse',如何修复 Matlab 中矢量注释头的错误对齐

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

代码

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);

给出了错误的矢量头对齐方式:

plot with reverse arrow

有什么解决办法吗?

最佳答案

处理该问题的一种方法是使用两个单独的注释创建箭头和线:

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

箭头坐标现在是 xac yac+2*yas xas -yas,

结果:

enter image description here

关于matlab - 如果 y 方向设置为 'reverse',如何修复 Matlab 中矢量注释头的错误对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55743582/

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