Is it possible to add X and Y axis lines to a plot in MATLAB?
6 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 25 Mar 2016
I would like to have lines drawn at 'x=0' and 'y=0' on my plot.
Accepted Answer
MathWorks Support Team
on 25 Mar 2016
This feature has been added in MATLAB 8.6(R2015b).
Please set 'XAxisLocation' and 'YAxisLocation' property to 'origin'. For details, please see the documentation.
If you are using a previous version, read the folllowing:
The ability to automatically draw lines at X = 0 and Y = 0 in an axes is not available in MATLAB. However, there is a simple way to manually add these lines to a plot.
For example, if you have the following plot
z = peaks(100);
plot(-49:50, z(:,26:5:50))
You can add the 0, 0 axis lines to it using the following code:
axh = gca; % use current axes
color = 'k'; % black, or [0 0 0]
linestyle = ':'; % dotted
line(get(axh,'XLim'), [0 0], 'Color', color, 'LineStyle', linestyle);
line([0 0], get(axh,'YLim'), 'Color', color, 'LineStyle', linestyle);
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!