shrey
shrey

Reputation: 223

How to reverse the direction of Y-Axis of MatLab figure generated by `imagesc()` function

I am trying to display data in a matrix using imagesc() function but it is showing row index in decreasing order (Assuming origin at left-bottom). Any idea what mistake i could be making or how to correct this?

The matrix only has zeros and ones in it.

enter image description here

Upvotes: 2

Views: 3903

Answers (2)

Dev-iL
Dev-iL

Reputation: 24169

There's another option which requires slightly less code:

axis ij

Reverse the coordinate system so that the y values increase from top to bottom.

As in this case (as it is already reversed), you could use

axis xy

To get back to normal, so that y values increases from bottom to top.

As mentioned in the docs of axis.

Upvotes: 1

Santhan Salai
Santhan Salai

Reputation: 3898

Set Ydir property of the current axes to normal

By default, imagesc uses reverse for YDir

set(gca,'YDir','normal');

See Documentation for Axes properties

Before:

enter image description here

After:

enter image description here

Note: This completely flips the inside data as well (it supposed to). As you are dealing with matrices, I hope this is what you want.

If you don't want to affect inside data, you need to change order of YTickLabels instead.

Upvotes: 3

Related Questions