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)
?
Change Axis LimitsCreate a line plot. Specify the axis limits using the xlim and ylim functions. For 3-D plots, use the zlim function. Pass the functions a two-element vector of the form [min max] .
Clear Axes and Reset All Axes PropertiesCreate a line plot and set the axis limits. Clear the line plot from the axes and reset all the axes properties to their default values. cla reset resets all properties of the current axes, except for the Position and Units properties.
The Axes Scaling Properties dialog box provides you with the ability to automatically zoom in on and zoom out of your data, and to scale the axes of the Time Scope. In the Time Scope menu, select Tools > Axes Scaling > Axes Scaling Properties to open this dialog box.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With