Is there a way to turn the y axis upside down in matlab plots, so that the positive direction of the y axis, instead of up, points down ?
(I beg of you; please do not say, print it out, then turn the paper around 😉
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
'YDir'axes property can be either'normal'or'reverse'. By default it is'normal'for most plots, but some plots will automatically change it to'reverse', such as theimageorimagescfunctions.You can set the y-axis direction of an axes with either the
setfunction or dot indexing (in newer MATLAB versions):I’m baffled by some of the other answers saying that the
'YDir'property has somehow disappeared or is giving an error. I haven’t seen any such behavior in versions of MATLAB from 2013, 2014, or 2016. There are only two potential pitfalls I came across:The property can’t be set with a cell array, only a character string:
although this works:
The
gcafunction can’t be used interchangeably as a handle when performing dot indexing (which is why I first saved it to a variablehin the above example):Finally, if you want some code that will toggle the
'YDir'property no matter what its current state is, you can do this: