MATLAB中3D表面上的附加轴

时间:2015-12-03 16:24:00

标签: matlab

假设我使用

绘制3d图形
[X,Y,Z] = peaks(25);
figure
surf(X,Y,Z);

如何在z = 0平面上添加带标签的附加x和y轴,如图中所示的红色?我想保持原轴不变。 enter image description here

1 个答案:

答案 0 :(得分:3)

我只想绘制自己的假轴。我不确定是否有更好的解决方案,但这个有效。

[X,Y,Z] = peaks(25);
figure
surf(X,Y,Z);

hold on;

%define the plot limits
xlim_arr = [-4 4];
ylim_arr = [-5 5];
zlim_arr = [-10 10];

%fix the limits of the real axes
xlim(xlim_arr);
ylim(ylim_arr);
zlim(zlim_arr);

%add grid and labels through all x-points
for i=xlim_arr(1):xlim_arr(2)
    plot3([i i],[ylim_arr(1) ylim_arr(2)], [0 0], 'Color', [0.7 0.7 0.7], 'LineWidth',0.4);

    text(i, ylim_arr(1)-0.4, 0, num2str(i));
    text(i, ylim_arr(2)+0.4, 0, num2str(i));
end

%add grid and labels through all y-points
for i=ylim_arr(1):ylim_arr(2)
    plot3([xlim_arr(1) xlim_arr(2)], [i i], [0 0], 'Color', [0.7 0.7 0.7], 'LineWidth',0.4);

    text(xlim_arr(1)-0.4, i, 0, num2str(i));
    text(xlim_arr(2)+0.4, i, 0, num2str(i));
end

%add the bold frame to highlight the fake axes
px = [xlim_arr(1) xlim_arr(1) xlim_arr(2) xlim_arr(2) xlim_arr(1)];
py = [ylim_arr(1) ylim_arr(2) ylim_arr(2) ylim_arr(1) ylim_arr(1)];
pz = [0 0 0 0 0];

plot3(px,py,pz, 'k', 'LineWidth', 0.5);

enter image description here

相关问题