Setting axes with center in origin (0,0) in plotted variables.

892 views (last 30 days)
Kasper on 12 May 2011
Commented: Jan Kappen on 3 May 2022
Hey community, I have two variables with x 1 double data. I am to plot these two in a plot, but would like to have the axes to be intersecting each other in origin (0,0). Instead in the axes are shown with intersecting at for example (-2000,-6), my lowest x-value is -1200, lowest y-value is -6. Here it would be great to have the x-axis through y=0, so that differences from y=0 easily can be seen graphically.
How would I do that, is there a command you could use in the script written, to make it move the axes? I have a large script to evaluate a lot of graphs in, so a MATLAB-command would be preferable to a tool in the figure builder.
The (simple) code used is as following:
%%person5 - Puls
hold on
title('Forsøgsperson #5 Ethanol Ekg Puls')
Hope that my question is understandable and that it can be done.

Accepted Answer

Walter Roberson
Walter Roberson on 12 May 2011

Sign in to comment.

More Answers (3)

Rini Varghese
Rini Varghese on 1 Mar 2018
I am sure you are aware of the most straightforward solution to this is now available directly through MATLAB's axes option:
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
  1 Comment
Jason Duvall
Jason Duvall on 18 Oct 2020
Why are you sure the OP was aware of this? If that was the case, the question probably would not have been posted.

Sign in to comment.

Arnaud Miege
Arnaud Miege on 12 May 2011
Does the axis command do the trick?

Muhammad Asif
Muhammad Asif on 12 Aug 2020
set(gca, 'XAxisLocation', 'origin', 'YAxisLocation', 'origin')

Community Treasure Hunt

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

Start Hunting!