3D plot: draw xy grid line on the middle of the plot box
2 views (last 30 days)
Show older comments
I have a 3D plot. The grid lines typically render at limiting planes of the plot box. I'd like them to render on a plane inside those limits. For example, I have a box that is +/-2 units in x, y, and z. I turn off the z grid. I'd like the xy grid to render in the xy plane at z=0. Is there a way to do this with out explicitly drawing lines manually?
2 Comments
William Rose
on 16 Apr 2025
You can move the axes in a 2D plot, as shown below. If you could move the axes in a 3D plot, maybe the gridlines would move too. But XAxisLocation and YAxis location seem ineffecual in a 3D plot.
x=-2:.05:2; y=2*sin(x*pi);
figure
plot(x,y); grid on
ax=gca; ax.XAxisLocation='origin'; ax.YAxisLocation='origin';
Here's the 3D version. The axis locations do not move to the origin, despite the command to do so.
x=-2:0.2:2; y=-2:0.2:2;
[X,Y]=meshgrid(x,y);
Z=-2+4*exp(-(X.^2+Y.^2)/4);
surf(X,Y,Z); grid on;
ax=gca; ax.XAxisLocation='origin'; ax.YAxisLocation='origin';
Maybe someone else knows the way to make it happen.
Answers (2)
William Rose
on 16 Apr 2025
x=-2:0.2:2; y=-2:0.2:2;
[X,Y]=meshgrid(x,y);
Z=-2+4*exp(-(X.^2+Y.^2)/4);
surf(X,Y,Z);
grid3(x,y,0)
You could edit the function to get black or gray grid points, if you prefer.
See Also
Categories
Find more on Axes Appearance 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!

