Any idea how to recreate this plot?

I have all the necessary data, windspeed as a function of height and time, wind direction in degrees also a function of height and time. I just cannot figure out how to plot a quiver plot on top of a pcolor plot
Any help would be great
Thanks

 Risposta accettata

Adam Danz
Adam Danz il 26 Mar 2023
Modificato: Adam Danz il 9 Apr 2023
> I just cannot figure out how to plot a quiver plot on top of a pcolor plot
Plot the pcolor data and then the quiver data.
I noticed that in your image, all of the quiver arrows look like they have the same magnitude. I assume this is part of your data, otherwise you'll need to adjust the u and v values. The arrows in this demo do not have the same magnitude.
load wind
x = x(:,:,3);
y = y(:,:,3);
u = u(:,:,3);
v = v(:,:,3);
pcolor(x,y,u);
hold on
quiver(x,y,u,v, 'k-','LineWidth',1.5)
Update: rescaling with datetime
Currently quiver does not accept datetime which is why the datetime values are converted to numeric. But the numeric values are very large which causes issues with scaling quiver arrows. I noticed your timestamps only span the course of a day so there's no need to use gigantic x values.
This solution converts your datetime values to minute from midnight. You've got about 1425 minutes and your y values ranges about 2000 so the plot aspect ratio will be more reasonable.
See in-line comments for details.
% Load data
load('test_var.mat');
% Convert numeric timestamps to datetime
timestamps = datetime(T_wind_30min,'ConvertFrom','datenum');
% Shift all timestamps by the stating date
baseDate = dateshift(min(timestamps(:)),'start','day');
timestampsShift = timestamps - baseDate;
% Convert timestamps to minutes from the start of the first day in the data
timeMinutes = minutes(timestampsShift);
% Plot pcolor
f1=figure();
Y=pcolor(timeMinutes,H_wind_30min,dl_wind_out_day.dl_w_30min);
set(Y,'EdgeColor', 'none');
colormap(jet);
ylim([0 2000]);
cl=colorbar;cl=colorbar;
clim([-2,2])
% Add quiver
hold on
Q=quiver(timeMinutes, H_wind_30min, xWind_unit_30min, yWind_unit_30min, 'k-');
% Set xaxis datetime tick labels
baseDate.Format = 'HH:mm';
xt = 0 : 180 : 1400;
xtlab = string(baseDate + minutes(xt));
set(gca, 'XTick', xt, 'XTickLabel', xtlab)

14 Commenti

Ajmal Rasheeda Satheesh
Ajmal Rasheeda Satheesh il 26 Mar 2023
Modificato: Adam Danz il 27 Mar 2023
I tried your solution, but I am ending up with this?
Experiment with
grid off
Hi
Still the same result
We don't have enough information to understand whether the issue is with the data, the implementation of the solution, or something else.
The quiver seems to work without x and y, but when i set x as datenum data and y as height, everything becomes straight lines
Can you produce a simple demo that reproduces the problem?
I started playing around with the scale of quiver and now the straight line issue is gone, but the arrows are too small to actually see the arrows on the plot
Adam Danz
Adam Danz il 1 Apr 2023
Modificato: Adam Danz il 1 Apr 2023
Again, it would be much easier to work with a simple demo that we can run and reproduce on our end. I don't know what is supposed to be arrows on the plot above.
Arrows are the wind directions from the quiver function
These are the variables and the demo code that can be used to reproduce the plot that I got
Thanks
I ran your code in R2022a and was able to reproduce the horizontal lines when I didn't use quiver scaling and the small arrows you described when using your quiver scaling values.
To understand why we're seeing mostly horizontal lines let's look closer at your data.
The horizontal vector components are relatively larger in magnitude than the vertical components so we can expect some amount of horizontal dominance. The plot below shows the distributions of your horizontal (top) and vertical (bottom) vector components (u,v).
More importantly, look at the aspect ratio of your data and plot. The range of x values is about 0.98 (range(xlim)) while the range of y values is 2000 (range(ylim)). That means vertical components of the vector need to be much larger than horizontal components to avoid horizontal quiver lines.
As you discovered, you need to scale down the vectors since their magnitudes are much larger than the x-axis range but they are also much smaller than the y-axis range. Since the size of the arrow head depends on the magnitude of the quiver arrow, there's not much you can do to show the arrow heads with these data. Note, there is a MaxHeadSize property but increasing that value didn't help in this case.
If that still isn't clear, let' look at just your quiver data.
load('test_var.mat');
scale = .001;
Q=quiver(T_wind_30min, H_wind_30min, xWind_unit_30min, yWind_unit_30min, scale,'k-',LineWidth=0.2);
Q.MaxHeadSize = 1;
xlabel('Small x range, large horizontal components')
ylabel('Large y range, small horizontal components')
Now let's zoom into the area circled in red.
It looks like a single flat line but if we set the axes' aspect ratio to 1:1 we can see the quiver arrows.
axis equal
I guessed the range between x and y axis was the issue too, but the thing is my axis is datetime in datenum. Is there any way to get the arrows to show up?, some kind of normalization of the horizontal wind values?
I've updated my answer to show how to rescale your data.

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by