Any idea how to recreate this plot?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천

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?
Experiment with
grid off
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.
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?

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.
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?
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
