3d - Different Axes Positions in MATLAB -
i'm trying shift axes positions in matlab figure. i'd achieve similar (which done in gnuplot):
i don't have idea whether possible @ all, or might find answer, appreciated.
hmm....
so let's plot:
x = zeros(1,21); y = -10:10; z = y/2; figure; plot3(x,y,z); % line (0,-10,-5) (0,10,5) similar example
well, 1 problem matlab doesn't automatically plot coordinate axis you've shown there. discussed here: how show x , y axes in matlab graph?
to plot (in 3d), cheap solution is:
locs = axis; % current axis boundaries hold on; plot3([locs(1) locs(2)], [0 0], [0 0]); %plot xaxis, line between(-x,0,0) , (x,0,0); plot3([0 0], [locs(3) locs(4)], [0 0]); %plot y axis, line (0,-y,0) , (0,y,0); plot3([0 0], [0 0], [locs(5) locs(6)]); % plot z axis hold off
just gnu plot, 3d matlab plot "in box." unlike gnu plot, matlab box isn't outlined. if want outline you'll have draw lines too...ugh.
% lets plot 12 lines make box in black ('k'); hold on; % hold x constant , plot 4 parallel-to-x lines; plot3([locs(1) locs(2)], [locs(3) locs(3)], [locs(5) locs(5)],'k'); % (-x,-y,-z) (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;
now have box;
if want area y>0,z>0; can use axis command. using axis after plotting other lines messed me, decide on limits @ beginning.
all together:
figure; plot3(x,y,z); % line (0,-10,-5) (0,10,5) similar 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, line between(-x,0,0) , (x,0,0); plot3([0 0], [locs(3) locs(4)], [0 0]); %plot y axis, line (0,-y,0) , (0,y,0); plot3([0 0], [0 0], [locs(5) locs(6)]); % plot z axis % plot box % hold x constant , plot 4 parallel-to-x lines; plot3([locs(1) locs(2)], [locs(3) locs(3)], [locs(5) locs(5)],'k'); % (-x,-y,-z) (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;
i'm sure can make better, think that's start. put mess function save typing.
Comments
Post a Comment