Plotting multiple Contour filled plots in one MATLAB figure i.e.(like slices along z-axis).
23 次查看(过去 30 天)
显示 更早的评论
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.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/740664/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/740664/image.jpeg)
回答(1 个)
Jaswanth
2024-2-15
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1617748/image.png)
I hope the information provided above is helpful in accomplishing your task.
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!