Quiver. Make wind scale of 1m/s inside plot

I have had a really tough time thinking of a way to show a scale of the wind vectors that Im plotting.
Im using quiversc(lon,lat,u,v) but I dont know how to put a magnitude of reference (1 m/s for example) , as in the plot below.
Thanks!

 Accepted Answer

[x, y] = meshgrid(-2:.2:2);
z = x.*exp(-x.^2-y.^2);
[dx, dy] = gradient(z, 0.2);
sc = 'off'; % scale
quiver(x,y,dx,dy, sc);
axis tight;
hold on
a = axis;
% posision of the ref arrow
xr = a(1)+0.1*(a(2)-a(1));
yr = a(4)-0.1*(a(4)-a(3));
quiver(xr, yr, 1, 0, sc) % unit lenght

6 Comments

Hi, thank you very much for your answer!
I think I didnt explain very well. My question is related to give the plot a vector magnitude reference. Specifically to indicate the size of an arrow that has 1 m/s as the magnitude. That way, the plot can help to see if other vectors are more or less faster
Chunru
Chunru on 21 Sep 2023
Edited: Chunru on 21 Sep 2023
See the edited above
Thanks! So I deactivated the scaling, but now the arrows are very tiny so I cant see anyone, not even the reference (which i cant find). This is my code (its into a subplot for cycle so I will only put the important parts and a plot of reference)
quiver(LON, LAT, u, v, sc,'k')
hold on
a = axis;
xr = a(1)+0.1*(a(2)-a(1));
yr = a(4)-0.1*(a(4)-a(3));
quiver(xr, yr, 1, 0, sc,'r') % unit lenght
You can change ux(=1) to any suitable value to make it visible and label it with the appropriate magnitude and unit for reference.
You may also want to change to the following:
manual_sc = 100; % adjust this val
quiver(LON, LAT, manual_sc*u, manual_sc*v, sc,'k')
Or you can post your data if you need further help.
Hi thank you very much! Thanks to your code I manage to do some arrangements, even put the reference arrow to fit more in the plot.
However I have some doubts about it. My code is this one (I use quiversc instead of quiver to control the density of the arrows, but the scaling is the same, I corroborated that):
quiversc(LON,LAT,u*2.5,v*2.5,'off','k','density',60,'LineWidth',1) % off is for scaling
colormap(brewermap(10,'PuBuGn'))
caxis([0 5])
borders('countries','k','LineWidth',1)
borders('countries','k','LineWidth',1)
axis equal
ylim([-30 36])
xlim([30 178])
yticks(-30:30:30)
yticklabels({'30°S','EQ','30°N'})
xticks(40:40:160)
xticklabels({'40°E','80°E','120°E','160°E'})
hold on
a = axis;
xr = a(1)+0.1*(a(2)-a(1));
yr = a(4)-0.1*(a(4)-a(3));
hold on
b = rectangle('Position',[xr-15 yr-6 15 12],'FaceColor','white');
hold on
quiver(xr-13,yr,1*12.5,0,'k','LineWidth',1,'MaxHeadSize',2.5)
The resulting plot is:
So my question is this: I put the manual_sc = 2.5 for the u,v values. Then, to show the reference arrow, I multiply it per 12.5. I understand that, if the whole quiver plot is adjusted with 2.5 and the reference arrow is adjusted with 12.5, then the reference arrow has a magnitude of 4 m/s? I thought about it cause its 4 times bigger than the main quiver plot vectors.
Hey I managed to realize that my question is resolved! I saw the measure of the reference arrow and its indeed the quantity I determined. Thank you so much for your answer, you helped me a lot to improve my plots and to give them a better style
I let my code available for the future if someone has a similar problem

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!