3D plot: draw xy grid line on the middle of the plot box
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
William Rose
2025-4-16
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.
回答(2 个)
William Rose
2025-4-16
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axes Appearance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


