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
採用された回答
> 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 件のコメント
Ajmal Rasheeda Satheesh
2023 年 3 月 26 日
編集済み: Adam Danz
2023 年 3 月 27 日

I tried your solution, but I am ending up with this?
Walter Roberson
2023 年 3 月 26 日
Experiment with
grid off
Ajmal Rasheeda Satheesh
2023 年 3 月 27 日
Hi
Still the same result
Adam Danz
2023 年 3 月 27 日
We don't have enough information to understand whether the issue is with the data, the implementation of the solution, or something else.
Ajmal Rasheeda Satheesh
2023 年 3 月 27 日
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
Walter Roberson
2023 年 3 月 27 日
Adam Danz
2023 年 3 月 27 日
Can you produce a simple demo that reproduces the problem?
Ajmal Rasheeda Satheesh
2023 年 3 月 31 日

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
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.
Ajmal Rasheeda Satheesh
2023 年 4 月 1 日
Arrows are the wind directions from the quiver function
Ajmal Rasheeda Satheesh
2023 年 4 月 7 日
These are the variables and the demo code that can be used to reproduce the plot that I got
Thanks
Adam Danz
2023 年 4 月 7 日
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

Ajmal Rasheeda Satheesh
2023 年 4 月 8 日
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?
Adam Danz
2023 年 4 月 9 日
I've updated my answer to show how to rescale your data.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Vector Fields についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
