简体   繁体   中英

How can I remove the back faces of a 3D matlab plot

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)

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

This flickers, but it works. The function can be used as set_walls(gca, 'zmin')

移除背景

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM