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

Colin T Bowers
  • 18,106
  • 8
  • 61
  • 89
Isopycnal Oscillation
  • 3,234
  • 6
  • 21
  • 37
  • 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... – noufal Apr 22 '13 at 04:04
  • Are you saying that you no longer have `x` and `y` in memory? – Dan Apr 22 '13 at 06:47
  • @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 Apr 22 '13 at 19:35
  • @dan Yes, I do have them in memory. – Isopycnal Oscillation Apr 22 '13 at 19:35
  • If they are in memory then why not just go `plot(y,x)`? – Dan Apr 23 '13 at 06:19
  • @IsopycnalOscillation fine... I didn't think about such a case. . . – noufal Apr 24 '13 at 16:09

1 Answers1

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.

Colin T Bowers
  • 18,106
  • 8
  • 61
  • 89