我正在尝试在Matlab图中移动轴位置。我想实现与此类似的东西(在gnuplot中完成):
我不知道这是否可行,或者我可能找到答案,所以任何帮助都将不胜感激。
答案 0 :(得分:6)
...嗯
所以让我们的情节:
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没有像你在那里那样自动绘制坐标轴。 这在这里讨论: How to show x and y axes in a MATLAB graph?
要绘制那些(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图是一个盒子里的#34;"与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;
我相信你可以做得更好,但我认为这是一个非常好的开始。我会把所有这些混乱放入一个函数来保存输入。