8

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

4
  • 2
    the LineSpec is generally a string such as '-k' for a black line, and 'filled' refers to the point markers which can be specified. For example '-sk' which gives squares however these will replace the arrows heads from quiver. To modify the quivers I suggest you take a look at this previous question.
    – RTL
    Commented Apr 7, 2014 at 12:06
  • @RTL : Thanks for the reference for the other question it is indeed helpful, but I figure (as suggested by the docs) there should be a simpler way to do this. Regarding LineSpec, it is a good direction but the specifiers do not to include all the regular specs in general and specifically : "quiver(x,y,u,v,'Linestyle','-sk')" seem not to be a valid syntax.
    – Ohad Dan
    Commented Apr 7, 2014 at 12:18
  • try quiver(x,y,u,v,'-sk') the 'linestyle' is not needed. I'm afraid I don't know of a simpler way... (its worth comparing with quiver(x,y,u,v,'-sk','filled') to see the effect of filled)
    – RTL
    Commented Apr 7, 2014 at 12:21
  • What you're asking is not easy to achieve as Matlab constructs every arrow in the quiver plot from to line objects: one for the tail and one for the head. Thus, the style of the arrow head cannot be changed like for annotation('arrow',...). A possible approach would be to replace every arrow head line object with a polygon using fill(...).
    – Deve
    Commented Apr 9, 2014 at 8:56

2 Answers 2

3

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.

1
  • Sorry, messed up different approaches. I updated the code, now it should work. Thanks for the correction! Commented Apr 16, 2014 at 8:42
0

This code in an answer to a similar question works quite well, actually. It uses annotations.

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

1
  • 2
    Please give a brief description of what that question page's content is and how does it solve this question.
    – CPHPython
    Commented Jan 17, 2017 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.