Filled contour plot on other planes (X-Z or Y-Z)
20 次查看(过去 30 天)
显示 更早的评论
Hello I was looking for a nice way to visualize my 3D data.
Firstly, I did it using slices of pcolor plots in different place.
However, it's hard to interpret values like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1291565/image.png)
So I was trying to repeat this plot with contourf but it only allows plotting in X-Y plane.
Is any possibility to create filled contours in other planes?
I found only the contourslice function for contours.
0 个评论
采纳的回答
Benjamin Kraus
2023-2-13
contourf works fine when used with an hgtransform, except it is not updating the automatically selected limits correctly, so you will need to update the limits to make sure your rotated contour object is visible in the axes.
I'm not quite sure why you are getting the error "The new value for the Matrix property may cause rendering problems.", but I suspect it has nothing to do with contour, but rather the specific Matrix you are using is not well defined. If you can provide the specific matrix that you used that produced that error message, that would be helpful to get a better idea of why you get that error message.
Considering the example code you provided one of your comments, with some small modifications:
% Default Matrix (eye(4)) works fine, as expected:
fig = figure;
ax = axes('Parent',fig);
t = hgtransform('Parent',ax);
Z = peaks;
contourf(Z,32,':','Parent',t);
% Rotating 90 degrees around X moves the contour into the X/Z plane, and
% requires updating the limits and view.
fig = figure;
ax = axes('Parent',fig);
t = hgtransform('Parent',ax);
Z = peaks;
contourf(Z,32,':','Parent',t);
t.Matrix = makehgtform('xrotate',pi/2);
ylim([-1 1])
zlim([1 49]);
view(0,0)
% The contour starts out at z = 0, x = [1 49], and y = [1 49]. If you
% rotate 45 degrees around the X-axis, the new location is:
% x = [1 49]
% y = sqrt(2)/2.*[1 49]
% z = sqrt(2)/2.*[1 49]
beforeX = [1 49];
beforeY = [1 49];
beforeZ = [0 0];
beforeLim = [beforeX; beforeY; beforeZ; [0 0]];
transformationMatrix = makehgtform('xrotate',pi/4);
afterLim = transformationMatrix*beforeLim;
afterX = afterLim(1,:);
afterY = afterLim(2,:);
afterZ = afterLim(3,:);
fig = figure;
ax = axes('Parent',fig);
t = hgtransform('Parent',ax);
Z = peaks;
contourf(Z,32,':','Parent',t);
t.Matrix = transformationMatrix;
xlim(afterX)
ylim(afterY)
zlim(afterZ)
% The contour starts out at z = 0, x = [1 49], and y = [1 49]. If you
% rotate 2 degrees (pi/90) around the Y-axis ([0 1 0]), the new location is:
% x = ~[1 49]
% y = ~[1 49]
% z = ~[-1.7 -0.03]
beforeX = [1 49];
beforeY = [1 49];
beforeZ = [0 0];
beforeLim = [beforeX; beforeY; beforeZ; [0 0]];
transformationMatrix = makehgtform('axisrotate',[0 1 0],pi/90);
afterLim = transformationMatrix*beforeLim;
afterX = sort(afterLim(1,:));
afterY = sort(afterLim(2,:));
afterZ = sort(afterLim(3,:));
fig = figure;
ax = axes('Parent',fig);
t = hgtransform('Parent',ax);
Z = peaks;
contourf(Z,32,':','Parent',t);
t.Matrix = transformationMatrix;
xlim(afterX)
ylim(afterY)
zlim(afterZ)
% Note that makehgtform('axisrotate',[0 1 0],pi/90) is equivalent to
% makehgtform('yrotate',pi/90), so you will get the same answer.
mat1 = makehgtform('axisrotate',[0 1 0],pi/90)
mat2 = makehgtform('yrotate',pi/90)
isequal(mat1, mat2)
13 个评论
Benjamin Kraus
2023-2-15
编辑:Benjamin Kraus
2023-2-15
Thanks. This does seem to be a bug. I've reported the bug to the developers. In the meantime, if setting FaceAlpha to 0.99 works, I would continue doing that.
If I had to guess, when you set FaceAlpha to anything close to 1, there is an optimization that is being done for performance reasons that skips some transparency calculations, and the bug is in that pathway. When you set the FaceAlpha to <0.99, it will likely take longer to render, because it is doing extra transparency calculations, but it results in a more accurate picture.
更多回答(1 个)
Walter Roberson
2023-2-10
Create a hgtransform() and parent it to the axes. Extract a 2d slice of the volume (interpn() or even just array access and squeeze()) and contoutf() that, parenting it to the hgtransform (pass in the transform handle where you would pass in an axes). Now set the Matrix property of the transform to rotate it to the desired plane. makehgtform is very useful for creating the matrix.
Note that the rightmost transform in makehgtform is one executed first.
6 个评论
另请参阅
类别
在 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!