Matlab如何填充箭头箭头

时间:2014-04-07 11:50:05

标签: matlab plot

我正在制作quiver plot

[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;
figure
quiver(x,y,u,v)

我想要填充箭头(即enter image description here而不是enter image description here

从文档中,使用

应该非常简单
quiver(...,LineSpec,'filled')

但是,我仍然无法弄清楚正确的语法 - 这些不起作用:

quiver(x,y,u,v,'LineWidth','filled');
quiver(x,y,u,v,'LineWidth',1,'filled');

感谢您的帮助!


编辑:使用行说明符执行以下操作:

quiver(x,y,u,v) %Original

enter image description here

quiver(x,y,u,v,'-sk','filled') %With line specifiers

enter image description here

2 个答案:

答案 0 :(得分:3)

我不是MATLAB专业人士,所以请原谅我的答案是否笨拙。我相信有更优雅的方法可以解决这个问题 - 以下是我找到的方法。

我决定解决此问题,检索箭头提示的位置,删除它们并用fill重新绘制它们(如Deve建议的那样)。我注意到我可以告诉fill一个多边形结束,下一个多边形通过插入NaN值开始(这也就像绘制原始箭头的方式一样,正如您所看到的那样检查原始{{1} })。这样做我失去了影响物体颜色的可能性,并且它们没有被填满。作为一个解决方案,我在循环中绘制了新的箭头提示 - 我知道可能有更好的方法来做到这一点,所以我很高兴任何添加。

我使用了你给出的例子,只用了替换最后一行 XData获得情节的处理。从那里开始:

HANDLE = quiver(x,y,u,v);

然后,您可以在ArrowTips变量中找到箭头提示的句柄。您可以在children=get(handle,'children'); % retrieve the plot-children - % second element are the arrow tips XData=get(children(2),'XData'); % retrieve the coordinates of the tips YData=get(children(2),'YData'); hold on delete(children(2)) % delete old arrow tips for l=1:4:length(XData)-3 % paint new arrow tips, skipping the NaN-values ArrowTips((l-1)/4+1)=fill(XData(l:l+2),YData(l:l+2),'r'); end 的调用中指定Edge-和Facecolor,分别为黑色和红色。

答案 1 :(得分:0)

这个代码在回答类似问题时实际上效果很好。它使用注释。

In Matlab how do I change the arrow head style in quiver plot?