How to plot spatial map of wind vectors according to a reference magnitude?

17 次查看(过去 30 天)
Hello all,
Till now, I have been using quiversc function (https://in.mathworks.com/matlabcentral/fileexchange/70338-climate-data-toolbox-for-matlab) in MATLAB for plotting wind direction in arrows since this function comes with the option to set the density of the arrows (but quiver function doesn't provide this option). Both of the functions only have the option 'scale' which is only to set the length of the arrows automatically to fit within the grid and then stretches them by the factor scale (scale = 2 doubles their relative length, and scale = 0.5 halves the length). But, I want to plot spatial map of wind vectors according to a reference magnitude (e.g., 2 m/s) and then add this reference vector as a legend. For your convenience, I am attaching a screenshot of a sample figure taken from the research paper Ding et al. (2021). Also, I have gone through a previous conversation (https://in.mathworks.com/matlabcentral/answers/94454-how-does-quiver-scale-the-vectors-it-plots?s_tid=answers_rc1-3_p3_MLT), where someone suggested that one can manually set scale of the quiver by setting 'AutoScale' to 'off'. So, I tried the following code:
scale_factor = 2;
quiversc(X,Y,U*scale_factor,V*scale_factor,'density',15,'MaxHeadSize',0.1,'AutoScale','off','color','k');
where, X and Y is the longitude and latitude, respectively. And U and V is the zonal and meridional wind components, respectively.
But, this results in very large arrows, which doesn't apper good. When I change scale_factor to 0.2, it looks good. I think that this code also only deals with the length of the arrows. It doesn't consider scale_factor of 2 as a reference magnitude, i.e., 2 m/s. So, is there any way that I can plot the wind vectors after scaling according to a given reference magnitude and then add in the legend? How can I decide the scale if I want to set the arrow lengths as per say 4 m/s or so? Can anyone please guide me in this regard? That will be really helpful for me. Thank you for your time and consideration.
With regards,
Ankan

采纳的回答

Mathieu NOE
Mathieu NOE 2024-1-5
I usually avoid doing this, but I ended up modifying slightly the original quiversc function (renamed here quiversc2 to avoid any conflict) so that it will correct the arrow lenght and apply a scale factor accordingly to your request
here a small demo script with the regular quiver and with the modified quiversc2 code.
My modification have 2 purposes :
1 - correct the resize effects (in the original quiversc code) - I noticed that the arrow lenght differ slightly before / after the imresize operations
2 - apply the requested scale factor
the scale factor is simply the inverse or your reference magnitude. so a arrow of 2 m/s will be displayed with length = 1 if your consider a reference magnitude = 2 m/s
% some dummy data ( arrows of length 2 m/s)
x = [0 0;0 0];
y = [0 0 ;5 5];
u = [2 0;2 0];
v = [0 2;0 2];
reference_magnitude = 2; %(e.g., 2 m/s)
scale_factor = 1/reference_magnitude;
% test with quiver
figure(1)
quiver(x,y,u*scale_factor,v*scale_factor,'AutoScale','off')
axis equal
% test with modified quiversc.m (hence quiversc2.m)
figure(2)
quiversc2(x,y,u*scale_factor,v*scale_factor,'AutoScale','off','Density',10); %
axis equal

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by