MATLAB Answers

How do I reverse the y-axis in image?

2.433 views (last 30 days)
Ali
Ali on 25 Nov 2014
The image function reverses the y-axis so I wanted to reverse it to correct it. I know it has something to do with gca but cannot figure out the right code. Please help me.

  0 Comments

Sign in to comment.

Accepted Answer

Orion
Orion on 25 Nov 2014
Edited: MathWorks Support Team on 27 Nov 2018
You can change the direction of increasing values along the y-axis by setting the YDir property of the Axes object.
If you want the values to increase from bottom to top (2-D view), then set the value to 'normal'. Alternatively, if you want the values to decrease from bottom to top, then set the value to 'reverse'. For example:
ax = gca;
ax.YDir = 'normal'

  2 Comments

Ali
Ali on 25 Nov 2014
But my instructor says its not a good idea to reverse the axis because this may cause problems when you add further things. Any idea why?
Royi Avital
Royi Avital on 1 May 2018
The problem is this operation also flips the data.

Sign in to comment.

More Answers (3)

Chad Greene
Chad Greene on 25 Nov 2014
And another solution:
axis ij

  0 Comments

Sign in to comment.


Wagih Abu Rowin
Wagih Abu Rowin on 5 Oct 2018
set(gca,'Ydir','reverse')

  1 Comment

Shushobhit Chaudhary
Shushobhit Chaudhary on 28 May 2019
This is the best answer. Thanks a lot. It helped me a lot.

Sign in to comment.


Shane
Shane on 25 Nov 2014
Alternatively, you can flip the array. Either fliplr or flipud Flip Left-Right, or Up-Down, depending on how your data is.
plot(X, fliplr(Y))

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags


Translated by