Hot to get a filled "contourslice" plot?
13 views (last 30 days)
Show older comments
Hi,
I am working with sliced plots of 3D data using "contourslice". I would like to have those contour plots filled just like using "contourf" in 2D. There seems to be no way to do this straight out, but I have identified that those contours are patch objects. I am trying to fill them changing the 'FaceColor', but nothing happens.
Anyone knows how to get those contours filled?
THANKS!
2 Comments
Laurens Bakker
on 27 Feb 2012
What do you want filled? The contours, the slices, both but with different colours, or something else?
Several properties influence the appearance of the faces of a patch object. Have you taken a look at <http://www.mathworks.nl/help/techdoc/ref/patch_props.html>?
Simon
on 6 Jun 2013
Edited: Simon
on 6 Jun 2013
I also have this problem. Perhaps it is a bug.
patchhandle=contourslice(X,T,Z,Q,[],T(1:5:end),[],[1 1]); set(patchhandle(:),'facecolor',[1 1 1])
The set statement does not fill the patches as expected. I have also played with lighting, etc. to no avail.
What needs to be set to make the patch objects from contourslice visibly filled?
Answers (1)
Nick Jacek
on 6 Aug 2021
There is no single function to create the kind of plots you describe, but I've notified the developers that there is desire for one to be added. However, one way to get the same effect is to first use interp3 to interpolate the values of your volumetric data along a particular slice and then create a filled contour plot of the result using contourf. This is shown in the following code snippet:
% Load 3D example data
[x, y, z, v] = flow;
% Find the minimum and maximum x and y coordinates of the data
xmin = min(x(:));
xmax = max(x(:));
ymin = min(y(:));
ymax = max(y(:));
% Calculate the x and y coordinates of 100 by 100 grid of points
[xcoord, ycoord] = meshgrid(linspace(xmin, xmax, 100), ...
linspace(ymin, ymax, 100));
% In the slice we are looking at, the z coordinate of every point is 0
zcoord = zeros(100,100);
% Interpolate the data to find a value for each point in the slice
s = interp3(x, y, z, v, xcoord, ycoord, zcoord);
% Plot the slice with filled contours
contourf(xcoord, ycoord, s);

0 Comments
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!