Plotting multiple Contour filled plots in one MATLAB figure i.e.(like slices along z-axis).

30 views (last 30 days)
i have some figures generated by MATLAB using contourf (contour filled) which i have attached the files as saved matlab figures.
I wanted to plot the figures i.e. 6 slices in one matlab figure on top of the other i have attached the picture of the desired output as well. I have been trying to figure out the way, methodology or matlab command to plot the results in the way needed but couldn't find the right approach. your help will be highly appreciated.

Answers (1)

Jaswanth
Jaswanth on 15 Feb 2024
Hi,
Based on your description, you're looking to overlay filled contour plots from six separate MATLAB figure files into a single 3D plot, where each contour plot is stacked vertically to visualize the slices together.
Kindly go through the following steps that can help you visualize the stacked 3D plot similar to the reference image you have provided:
  • Loading .fig files: The code opens .fig files invisibly, which means they are loaded into memory but not displayed on the screen.
fig1 = openfig('slice1.fig', 'invisible');
fig2 = openfig('slice2.fig', 'invisible');
...
  • Creating an array of figure handles:
figHandles = {fig1, fig2, fig3, fig4, fig5, fig6};
  • Setting up a new figure for overlaying plots:
figOverlay = figure;
hold on;
  • Defining a z-offset for layering contours: A z-offset is set to separate the contours in the z-dimension when plotted.
zOffset = 50;
  • Looping through figure handles to extract contours:
for i = 1:numel(figHandles)
  • Extracting axes and contours from each figure:
axs = get(figHandles{i}, 'Children');
  • Looping through axes to find Contour objects:
for k = 1:numel(axs)
  • Extracting contour data and plotting: The contour data is extracted from the ContourMatrix property of the contour object, and a while loop processes each contour segment.
while index < size(contourMatrix, 2)
  • Creating 3D contour patches: The patch function is used to create filled contour areas in 3D space, with the z-offset applied to separate the layers.
patch(x, y, z + zOffset * (i - 1), z, 'EdgeColor', 'none');
  • Adjusting the view to 3D and adding a color bar:
view(3);
colorbar;
  • Finalizing the plot and closing original figures:
hold off;
axis vis3d;
for i = 1:numel(figHandles)
close(figHandles{i});
end
The below visualization was generated utilizing the provided slice files.
I hope the information provided above is helpful in accomplishing your task.

Categories

Find more on Contour Plots in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!