Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab how to fill quiver arrow heads

Tags:

plot

matlab

I am making a 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)

I want the arrow heads to be filled (i.e enter image description here and not enter image description here)

From the documentation, it should be pretty straightforward by using

quiver(...,LineSpec,'filled')

However, I still couldn't figure out the right syntax - these do not work :

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

Thanks for your help!


edit : Using line specifiers does the following:

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

enter image description here

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

enter image description here

like image 613
Ohad Dan Avatar asked Apr 07 '14 11:04

Ohad Dan


1 Answers

I am not a MATLAB professional, so please excuse if my answer is clunky. I am sure there are more elegant ways to solve this - the following is the one I found.

I decided to solve this retrieving the positions of the arrow tips, deleting them and repaint them with fill (like Deve suggested). I noticed that I can tell fill that one polygon ends and the next begins through inserting NaN values (thats also the way the original arrow tips are drawn, as you can see inspecting the original XData). Doing so I lost the possibility to influence the color of the objects and they didn´t get filled. As a work-around I painted the new arrow-tips in a loop - I know there might be a better way to do it, so I am happy about any addition.

I used the example you gave, only replacing the last line by HANDLE = quiver(x,y,u,v); to get the handle to the plot. From there on:

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

You can then find the handles to the arrow-tips in the ArrowTips-variable. Feel free to specify the Edge- and Facecolor in the call to fill, here being black and red respectively.

like image 87
Paul Paulsen Avatar answered Sep 29 '22 12:09

Paul Paulsen