Azzera filtri
Azzera filtri

How do combine a contour plot with slice planes?

4 visualizzazioni (ultimi 30 giorni)
Miguel Olvera
Miguel Olvera il 21 Mar 2024
Risposto: SAI SRUJAN il 11 Apr 2024
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);

Risposte (1)

SAI SRUJAN
SAI SRUJAN il 11 Apr 2024
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!

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by