In Matlab how can I exchange the horizontal and vertical axes of an existing plot

Isopycnal Oscillation picture Isopycnal Oscillation · Apr 22, 2013 · Viewed 11k times · Source

Suppose I have vectors x and y, I know I can do plot(x,y) or plot(y,x) to achieve what I want. However, my question is specifically: If I have a plot already created in a figure as plot(x,y), how can I programmatically exchange the horizontal and vertical axes so that effectively I am saying plot(y,x)?

Answer

Colin T Bowers picture Colin T Bowers · Apr 22, 2013

Interesting question +1. The following example shows how to exchange the x and y axes of the current figure:

X = (1:100)'; %# Create x axis data
Y = randn(100, 1); %# Create y axis data
plot(X, Y); %# Plot the data
view(-90, 90) %# Swap the axes
set(gca, 'ydir', 'reverse'); %# Reverse the y-axis (Optional step)

Also, a relevant link to Matlab Central is here.