71 views (last 30 days)

Show older comments

Henry Giddens
on 6 Sep 2016

Edited: Henry Giddens
on 9 Sep 2016

Hi yu, Yes I have done it a few times. You should be aware that this will work for me because the scale on each axis is equal. For example:

%before this you have plotted a surface in axis hAx

axis(hAx,'equal')

%Get X, Y and Z data for plotting the axes...

X_range = hAx.XLim(2) - hAx.XLim(1);

X_start = hAx.XLim(1);

X_delta = X_range/20;

Y_delta = (hAx.YLim(2) - hAx.YLim(1))/20;

Y_start = hAx.YLim(1);

Z_delta = (hAx.ZLim(2) - hAx.ZLim(1))/20;

Z_start = hAx.ZLim(1);

X_Line = line(hAx,[X_start+X_delta X_start+X_delta*5],[Y_start+Y_delta Y_start+Y_delta],[Z_start+Z_delta Z_start+Z_delta]); % x Line

Y_Line = line(hAx,[X_start+X_delta X_start+X_delta],[Y_start+Y_delta Y_start+Y_delta*5],[Z_start+Z_delta Z_start+Z_delta]); % Y Line

Z_Line = line(hAx,[X_start+X_delta X_start+X_delta],[Y_start+Y_delta Y_start+Y_delta],[Z_start+Z_delta Z_start+Z_delta*5]); %Z Line

X_text = text(hAx,X_start+X_delta*6,Y_start+Y_delta,Z_start+Z_delta,'x');

Y_text = text(hAx,X_start+X_delta,Y_start+Y_delta*6,Z_start+Z_delta,'y');

Z_text = text(hAx,X_start+X_delta,Y_start+Y_delta,Z_start+Z_delta*6,'z');

You can then play around with how long you want each line, the colors of the lines and text etc... I tend to use linkprop to link the properties of the lines that need to stay the same. If you do not have equal axis scales, this method wont really work...

Henry

Divin Xavier
on 8 Jan 2021

Instead of Line command you could use annotation to get the arrow heads (version 2020b)

X_Line = annotation('textarrow',[X_start+X_delta X_start+X_delta*1.5],[Y_start+Y_delta Y_start+Y_delta],'Color','k'); % x Line

Y_Line = annotation('textarrow',[X_start+X_delta X_start+X_delta],[Y_start+Y_delta Y_start+Y_delta*1.5],'Color','k'); % Y Line

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!