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

1

10

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)?

Ingunna answered 22/4, 2013 at 2:17 Comment(6)
can you please share where does it practically needs to do? it seems to be quiet interesting though you have both the vectors ready in your hand...Shae
Are you saying that you no longer have x and y in memory?Washstand
@Shae I am using a GUI of which I have limited control (I am not allowed to fundamentally alter its structure although I can add on to it). The GUI spits out the plot with the axes arranged in a particular way of which I need the opposite. Since I have limited control over the GUI itself this is the only option...Ingunna
@dan Yes, I do have them in memory.Ingunna
If they are in memory then why not just go plot(y,x)?Washstand
@IsopycnalOscillation fine... I didn't think about such a case. . .Shae
P
9

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.

Pernod answered 22/4, 2013 at 6:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.