
How could one create a contourslice plot with the color fill property of a contourf plot?
조회 수: 4 (최근 30일)
이전 댓글 표시
As mentioned in the title, I am attempting to utilize the the function 'contourslice' in order to plot multiple 2-dimensional planes in series, representing data points on an X-Y grid at different depths, Z. I've successfully plotted two slices at different depths with 'contourslice' and I've also plotted one slice with 'contourf'. I find that it is easier to visual the data when the space between contour isolines is appropriately colored (as in 'contourf').
Is it possible to combine the filled isoline 'contourf' property with the multi-dimensional capability of 'contourslice'?
댓글 수: 0
답변 (1개)
Prathamesh
2025년 2월 18일
I understand that you are using the function 'contourslice' to plot multiple 2-dimensional planes in series, with the space between contour isolines colored for better visualization and are unsure if this can be combined with the multi-dimensional capability.
Here is an example code which achieves the same using ‘slice’ and ‘contourf’ functions :
Code:
% Example data
[X, Y, Z] = meshgrid(1:10, 1:10, 1:5); % Create a 3D grid
V = rand(10, 10, 5); % Random volumetric data
% Define the Z-levels you want to slice
zLevels = [1, 3, 5];
figure;
hold on;
% Plot contour lines using contourslice
contourslice(X, Y, Z, V, [], [], zLevels);
% Overlay filled contour plots manually
for i = 1:length(zLevels)
zLevel = zLevels(i);
% Extract the slice data
V_slice = V(:, :, zLevel);
% Create a contourf plot for the current slice
[~, h] = contourf(X(:, :, zLevel), Y(:, :, zLevel), V_slice);
% Adjust the ZData to position the contour plot in 3D space
for j = 1:length(h)
h(j).ZData = zLevel * ones(size(h(j).XData));
end
end
% Set the view to 3D
view(3);
xlabel('X');
ylabel('Y');
zlabel('Z');
colorbar;
grid on;
axis tight;
hold off;
title('Contour Slices with Filled Contours in 3D');
Output:

댓글 수: 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!