Using different colours in a quiver plot
28 views (last 30 days)
I am creating a 2D quiver plot and I need to show some of the arrows in the figure in a different colour from the rest. To illustrate the issue, I will use the example given on quiver documentation page (https://www.mathworks.com/help/matlab/ref/quiver.html).
Suppose I plot a quiver plot with custom scaling as follows:
close all hidden;
[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;
Now let us say that I want all arrows for which the vector magnitude is greater than 1.0 to be shown in red. I have tried to add the following code:
The result is as shown below:
Clearly, the second set of arrows have been scaled differently from the first set. I could work around this by manually adjusting the scale value in the second quiver command but this involves painstaking trial and error. May I know if there is a better solution?