问题描述
在matlab中绘制3d图形时,边界框的背面用白色填充:
When plotting a 3d graph in matlab, the back faces of the bounding box are filled in white:
这些可以很容易地通过以下方式全部删除
These can easily all be removed with
ax = gca;
ax.Color = [0, 0, 0, 0];
如何才能仅去除背面? (除了地板上的所有东西)
How can I remove just the rear sides? (everything but the floor)
推荐答案
使用未记录的Axes.Backdrop
属性,您可以得到这种行为. Axes.Backdrop.Face.VertexData
包含背景顶点的列表.我们可以找到并保持地板:
Using the undocumented Axes.Backdrop
property, you can sort of get this behaviour. Axes.Backdrop.Face.VertexData
contains a list of the vertices of the backdrop. We can find and keep the floor with:
ax = gca;
face = ax.Backdrop.Face;
% can be replaced with conditions on other axes and limits
point_on_face = face.VertexData(3,:) == ax.ZLim(1);
is_target_face = all(reshape(point_on_face, 4, []));
target_face_verts = logical(kron(is_target_face, ones(1, 4)));
% discard all but the first quad (the floor)
face.VertexData = face.VertexData(:,target_face_verts);
但是,当轴旋转时,将重新绘制这些四边形,这不是有效的解决方案.
However, when the axes are rotated, these quads are redrawn, making this not an effective solution.
我们可以通过添加事件侦听器来做进一步的工作:
We can go further by adding an event listener:
function h = set_walls(ax, varargin)
function update()
face = ax.Backdrop.Face;
data = face.VertexData;
if empty(data); return; end
keep_verts = false(1, size(data, 2));
for side = varargin'
side = side{:};
switch side
case 'xmin'; point_on_face = data(1,:) == ax.XLim(1);
case 'xmax'; point_on_face = data(1,:) == ax.XLim(2);
case 'ymin'; point_on_face = data(2,:) == ax.YLim(1);
case 'ymax'; point_on_face = data(2,:) == ax.YLim(2);
case 'zmin'; point_on_face = data(3,:) == ax.ZLim(1);
case 'zmax'; point_on_face = data(3,:) == ax.ZLim(2);
otherwise; error('Unknown face');
end
is_target_face = all(reshape(point_on_face, 4, []));
keep_verts = keep_verts | logical(kron(is_target_face, ones(1, 4)));
end
face.VertexData = data(:,keep_verts);
end
h = addlistener(ax, 'MarkedClean', @(x, y) update);
end
这会闪烁,但可以.该功能可用作set_walls(gca, 'zmin')
This flickers, but it works. The function can be used as set_walls(gca, 'zmin')
这篇关于如何删除3D Matlab图的背面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!