Is it possible to add X and Y axis lines to a plot in MATLAB?

6 views (last 30 days)

Accepted Answer

MathWorks Support Team
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);

More Answers (0)

Categories

Find more on Graphics in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!