필터 지우기
필터 지우기

How do combine a contour plot with slice planes?

조회 수: 4 (최근 30일)
Miguel Olvera
Miguel Olvera 2024년 3월 21일
답변: SAI SRUJAN 2024년 4월 11일
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);

답변 (1개)

SAI SRUJAN
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!

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by