In Matlab how can I exchange the horizontal and vertical axes of an existing plot
11,187
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.
Author by
Isopycnal Oscillation
Updated on July 20, 2022Comments
-
Isopycnal Oscillation almost 2 years
Suppose I have vectors x and y, I know I can do
plot(x,y)
orplot(y,x)
to achieve what I want. However, my question is specifically: If I have a plot already created in a figure asplot(x,y)
, how can I programmatically exchange the horizontal and vertical axes so that effectively I am sayingplot(y,x)
?-
noufal about 11 yearscan 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...
-
Dan about 11 yearsAre you saying that you no longer have
x
andy
in memory? -
Isopycnal Oscillation about 11 years@noufal 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...
-
Isopycnal Oscillation about 11 years@dan Yes, I do have them in memory.
-
Dan about 11 yearsIf they are in memory then why not just go
plot(y,x)
? -
noufal about 11 years@IsopycnalOscillation fine... I didn't think about such a case. . .
-