我目前正在尝试在 Matlab 图中移动轴位置。我想实现与此类似的东西(在 gnuplot 中完成):
我不知道这是否可能,或者我可以在哪里找到答案,所以任何帮助将不胜感激。
唔....
所以让我们绘制:
x = zeros(1,21); y = -10:10; z = y/2;
figure; plot3(x,y,z); % a line from (0,-10,-5) to (0,10,5) similar to the example
好吧,一个问题是 matlab 不会像您在此处显示的那样自动绘制坐标轴。此处对此进行了讨论: 如何在 MATLAB 图中显示 x 轴和 y 轴?
要绘制这些(在 3D 中),一个便宜的解决方案是:
locs = axis; % get current axis boundaries
hold on;
plot3([locs(1) locs(2)], [0 0], [0 0]); %plot xaxis, a line between(-x,0,0) and (x,0,0);
plot3([0 0], [locs(3) locs(4)], [0 0]); %plot y axis, the line (0,-y,0) and (0,y,0);
plot3([0 0], [0 0], [locs(5) locs(6)]); % plot z axis
hold off
就像那个 Gnu 图一样,3D matlab 图是“在一个盒子里”。与 Gnu 绘图不同,matlab 框没有轮廓。如果你想勾勒出你也必须画出那些线......呃。
% lets plot the 12 lines to make this box in black ('k');
hold on;
% hold x constant and plot 4 parallel-to-x lines;
plot3([locs(1) locs(2)], [locs(3) locs(3)], [locs(5) locs(5)],'k'); % (-x,-y,-z) to (x,-y,-z)
plot3([locs(1) locs(2)], [locs(3) locs(3)], [locs(6) locs(6)],'k');
plot3([locs(1) locs(2)], [locs(4) locs(4)], [locs(5) locs(5)],'k');
plot3([locs(1) locs(2)], [locs(4) locs(4)], [locs(6) locs(6)],'k');
% plot parallel-to-y lines
plot3([locs(1) locs(1)], [locs(3) locs(4)], [locs(5) locs(5)],'k');
plot3([locs(1) locs(1)], [locs(3) locs(4)], [locs(6) locs(6)],'k');
plot3([locs(2) locs(2)], [locs(3) locs(4)], [locs(5) locs(5)],'k');
plot3([locs(2) locs(2)], [locs(3) locs(4)], [locs(6) locs(6)],'k');
% plot parallel-to-z lines
plot3([locs(1) locs(1)], [locs(3) locs(3)], [locs(5) locs(6)],'k');
plot3([locs(1) locs(1)], [locs(4) locs(4)], [locs(5) locs(6)],'k');
plot3([locs(2) locs(2)], [locs(3) locs(3)], [locs(5) locs(6)],'k');
plot3([locs(2) locs(2)], [locs(4) locs(4)], [locs(5) locs(6)],'k');
hold off;
现在我们有了盒子;
如果我们只想要区域 y>0,z>0; 我们可以使用axis命令。在绘制所有其他线之后使用轴对我来说真的搞砸了一切,所以我会在一开始就决定你的限制。
全部一起:
figure;
plot3(x,y,z); % a line from (0,-10,-5) to (0,10,5) similar to the example
locs = axis;
axis([locs(1) locs(2) 0 locs(4) 0 locs(6)]);
locs = axis;
hold on;
% plot axis
plot3([locs(1) locs(2)], [0 0], [0 0]); %plot xaxis, a line between(-x,0,0) and (x,0,0);
plot3([0 0], [locs(3) locs(4)], [0 0]); %plot y axis, the line (0,-y,0) and (0,y,0);
plot3([0 0], [0 0], [locs(5) locs(6)]); % plot z axis
% plot box
% hold x constant and plot 4 parallel-to-x lines;
plot3([locs(1) locs(2)], [locs(3) locs(3)], [locs(5) locs(5)],'k'); % (-x,-y,-z) to (x,-y,-z)
plot3([locs(1) locs(2)], [locs(3) locs(3)], [locs(6) locs(6)],'k');
plot3([locs(1) locs(2)], [locs(4) locs(4)], [locs(5) locs(5)],'k');
plot3([locs(1) locs(2)], [locs(4) locs(4)], [locs(6) locs(6)],'k');
% plot parallel-to-y lines
plot3([locs(1) locs(1)], [locs(3) locs(4)], [locs(5) locs(5)],'k');
plot3([locs(1) locs(1)], [locs(3) locs(4)], [locs(6) locs(6)],'k');
plot3([locs(2) locs(2)], [locs(3) locs(4)], [locs(5) locs(5)],'k');
plot3([locs(2) locs(2)], [locs(3) locs(4)], [locs(6) locs(6)],'k');
% plot parallel-to-z lines
plot3([locs(1) locs(1)], [locs(3) locs(3)], [locs(5) locs(6)],'k');
plot3([locs(1) locs(1)], [locs(4) locs(4)], [locs(5) locs(6)],'k');
plot3([locs(2) locs(2)], [locs(3) locs(3)], [locs(5) locs(6)],'k');
plot3([locs(2) locs(2)], [locs(4) locs(4)], [locs(5) locs(6)],'k');
hold off;
我相信你可以做得更好,但我认为这是一个非常好的开始。我会把所有这些乱七八糟的东西放到一个函数中来保存打字。