How do combine a contour plot with slice planes?
9 ビュー (過去 30 日間)
古いコメントを表示
I am trying to reproduce the Master Plot figure, but am getting a very different result (Attempt). I can not figure out how to reduce the amount of slice planes in my attempt. I also can not figure out how to swap the y-axis with the z-axis. I also can not figure out how to manipulate the coordinate limits for the slice planes. I am unable to provide the raw data set because the file is very large.
numeric_matrix = cell2mat(numeric_data);
x = numeric_matrix(:, 1); % x (mm)
y = numeric_matrix(:, 2); % y (mm)
z = numeric_matrix(:, 3); % z (mm)
u = numeric_matrix(:, 4); % velocity in x axis
% Create a high-resolution grid
x_interp = linspace(-22, 22, 100); % Adjust range as needed
y_interp = linspace(-15, 5, 100); % Adjust range as needed
z_interp = linspace(min(z), max(z), 100); % Adjust range as needed
[X, Y, Z] = meshgrid(x_interp, y_interp, z_interp); % Create a 3-D grid
% Interpolate the velocity data onto the grid
U = griddata(x, y, z, u, X, Y, Z, 'nearest'); % Cubic interpolation
% Create a smooth filled contour plot
contourf(X(:,:,1), Y(:,:,1), U(:,:,1), 'LineStyle', 'none'); % Disable contour lines
hold on;
% Plot slice planes
yslice = linspace(-15, 5, 10);
zslice = linspace(min(z), max(z), 10);
slice(X, Y, Z, U, [], yslice, zslice); % Plot slice planes
colormap('jet');
colorbar;
xlabel('x (mm)');
ylabel('y (mm)');
zlabel('z (mm)');
title('3D Plot of u (m/s) with Contour Plot and Slice Planes');
view(3);
0 件のコメント
回答 (1 件)
SAI SRUJAN
2024 年 4 月 11 日
Hi Miguel,
I understand that you are facing an issue with plotting in MATLAB that combines a contour plot with slice planes through a 3D volume of data.
Please go through the following code sample to proceed further,
numeric_matrix = cell2mat(numeric_data);
x = numeric_matrix(:, 1); % x (mm)
y = numeric_matrix(:, 2); % y (mm) - Now acting as Z
z = numeric_matrix(:, 3); % z (mm) - Now acting as Y
u = numeric_matrix(:, 4); % velocity in x axis
% swaaping y and z.
% Create a high-resolution grid
x_interp = linspace(-22, 22, 100); % Adjust range as needed
y_interp = linspace(min(z), max(z), 100); % Adjust range as needed, now Z range
z_interp = linspace(-15, 5, 100); % Adjust range as needed, now Y range
[X, Z, Y] = meshgrid(x_interp, z_interp, y_interp); % Notice the swap in Y and Z
% Interpolate the velocity data onto the grid
U = griddata(x, z, y, u, X, Z, Y, 'nearest'); % Cubic interpolation, note the swap in Y and Z
% Create a smooth filled contour plot
contourf(X(:,:,1), Z(:,:,1), U(:,:,1), 'LineStyle', 'none'); % Disable contour lines
hold on;
% Plot slice planes with adjusted limits and fewer planes
yslice = linspace(min(z), max(z), 5); % Now Z slices, fewer planes
zslice = linspace(-15, 5, 5); % Now Y slices, fewer planes
slice(X, Y, Z, U, [], zslice, yslice); % Adjusted slice call
colormap('jet');
colorbar;
xlabel('x (mm)');
ylabel('z (mm)'); % Adjusted label
zlabel('y (mm)'); % Adjusted label
title('3D Plot of u (m/s) with Contour Plot and Slice Planes');
view(3); % Adjust view if necessary
I hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!