Plot multiple quiver keeping arrows magnitude proportion

14 views (last 30 days)
Hello! I have a simple question I am not able to solve properly. I will simplify the problem to the following:
Consider two sets of vector field data:
  • F1=(x,y,u,v)
  • F2=(x,y,2*u,2*v).
When I plot these data, the size of the arrows coming from F2 are the same as the ones coming from F1, despite the fact that they are actually doble length.
If I want quiver to autoscale the arrows, but to mantain the magnitue proportion between arrows for different data sets (by different calls to quiver), what is the best way of doing it?
An test code to show this issue is:
n=30;
x=randn(n,1);
y=randn(n,1);
u=randn(n,1);
v=randn(n,1);
quiver(x,y,u,v,'b');
hold on
quiver(x,y,2*u,2*v,'r')
legend('F1','F2')
hold off

Answers (1)

Hrishikesh Borate
Hrishikesh Borate on 19 Jul 2021
Edited: Hrishikesh Borate on 19 Jul 2021
Hi,
By default, the quiver function shortens arrows so they do not overlap. To disable automatic scaling so that arrow lengths are determined entirely by U and V, set the scale argument to 0. Following code demonstrates the same.
quiver(x,y,u,v,0,'b');
hold on
quiver(x,y,2*u,2*v,0,'r')
legend('F1','F2')
hold off
For more information, refer quiver.
  2 Comments
Marius Marinescu
Marius Marinescu on 19 Jul 2021
First of all thanks for your answer.
My question is slightly different. I want to keep the size proportion between "arrows" (for different calls to quiver) but at the same time let Matlab scale automatically the arrows so they do look good and have no overleap.
I have different data sets that can vary in magnitude, so in the way you asnwered me I have to guess a "good scale factor" for each time I use different data.
So ideally, I would like Matlab to scale automatically the data when I first call to quiver and after using hold on and call quiver again to add more (similar) data, I want that Matlab keeps or use the same scale factor as in the first one.
I think by the way is quiver programed now, it is not usefull to use hold on, since arrows are scaled automatically and independently for each call to quiver making arrows size incomparable.
Lastly, I have a related question that may help me to solve this issue. Is it possible to know the automatic scaling factor Matlab uses after executing quiver?

Sign in to comment.

Categories

Find more on Vector Fields in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!