r/matlab•
tfb-

How to make axes go through center of a surface?

TechnicalQuestion

I'm taking measurements off a surface but nothing would help me more than having the axes go through it's center rather than being on the sides, is there any way to do this?

Posted Jun 13, 2018, 2:48 PM UTC

310
poundSound•

You could just add another axis drawn manually using plot3 or surf.

2
EatMyPossum+6•
1
tfb-OP•

Yeah, I tried this but nothing happened. It's a 3D hollow shell type surface I'm looking at

1
123abc-123xyz+1•

I tried this but nothing happened

Dude, what? Can you be more vague? It's possible that maybe you just didn't get the implementation or syntax correct

1
NedDastyMatlab Pro•

This isn't possible in Matlab unfortunately. I'd translate your object so its mean position is zero instead.

1
agree-with-you•

I agree, this does not seem possible.

1
tfb-OP•

It is already centered at the origin but visually it would make all the difference for me. But thanks!

1
NedDastyMatlab Pro•

I'm a bit confused, if is centered at the origin then your axes should be going through its center--what's the problem?

1
tfb-OP•

I mean when you do a surface plot, the axes are automatically placed on the sides of the planes and not crossing in the center

1
NedDastyMatlab Pro•

Here's a quick start for what you may want:

fig = figure('Units','normalized','OuterPosition',[.2 .2 .6 .8]);
ax = axes('Parent',fig,'NextPlot','add','Position',[.2 0 .6 1],'Visible','on','XLim',[-2 2],'YLim',[-2 2],'ZLim',[-2 2],'Visible','off');
axis(ax,'square');

[X,Y,Z] = sphere(25);
s = surf(X,Y,Z);
s.FaceAlpha = 0.5;
view(45,25);

% plot x-y plane
X = [-2 2 2 -2]; Y = [-2 -2 2 2]; Z = zeros(4,4);
surf(X,Y,Z,'FaceColor','white','FaceAlpha',0.25,'EdgeColor','none');

% plot x-z plane
X = [-2 -2 2 2]; Y = [0 0 0 0]; Z = repmat([-2 2 2 -2]',1,4);
surf(X,Y,Z,'FaceColor','white','FaceAlpha',0.25,'EdgeColor','none');

% plot the y-z plane
X = [0 0 0 0]; Y = [-2 -2 2 2]; Z = repmat([-2 2 2 -2],4,1);
surf(X,Y,Z,'FaceColor','white','FaceAlpha',0.25,'EdgeColor','none');

% plot axis lines
grey = [.5 .5 .5];
plot3([-2 2],[0 0],[0 0],'Color',grey);
plot3([0 0],[-2 2],[0 0],'Color',grey);
plot3([0 0],[0 0],[-2 2],'Color',grey);

lighting('gouraud');
camlight;
1