Adding scatter points to a contour plot

28 ビュー (過去 30 日間)
Hussein Kokash
Hussein Kokash 2023 年 2 月 3 日
回答済み: Star Strider 2023 年 2 月 3 日
Hello,
I have the following plot code:
% Plot the RMS velocity contour
contourf(X, Y, rms_velocity_U);
colorbar;
xlabel('X');
ylabel('Y');
title(sprintf('RMS Velocity Contour at t=%f', time(i)));
This plot plots the rms velocity values in a plane x,y.
X, Y, and rms_velocity_U are 67*67 matrices.
At each x position, I want to find the highest "rms_velocity_U" value, in total would be 67 values and I want to add them to the plot below as a scatter points.
Any way to calculate the value and position of these point and add them to the plot?
Thanks

回答 (1 件)

Star Strider
Star Strider 2023 年 2 月 3 日
‘Highest’ usually implies one value, not 67, and without your data (the (67x67) matrix) and understanding what the ‘highest 67 values’ means, plotting them is not possible.
That aside, marking the highest 5 values in a contourf plot is straightforward —
[X,Y,Z] = peaks(50);
[Zmax,idx] = maxk(Z(:),5)
Zmax = 5×1
8.0436 8.0223 8.0012 7.9869 7.8209
idx = 5×1
1238 1288 1239 1289 1188
figure
contourf(X, Y, Z, 20)
colormap(turbo)
hold on
plot(X(idx), Y(idx), 'pg', 'MarkerSize',10, 'MarkerFaceColor','g')
hold off
xlabel('X')
ylabel('Y')
See the documentation on maxk (introduced in R2017b) for details.
Use a similar approach with your data.
.

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by