Reputation: 45
While editing a .fig matlab file, I want to swap the x and y axes without redrawing the plot by code (without changing the order of vector data). Does a solution exist to my problem? Is there some option in the figure properties menu? Thanks in advance.
Upvotes: 0
Views: 1989
Reputation: 13945
In addition to Luis 's answer you can set the current axes View
property to [90 -90]
directly from the property inspector.
Programmatically this is equivalent to this:
set(gca,'View',[90 -90])
Note:
Thanks to Luis for the correction. Using [-90 90]
does swap the axis but then you need to reverse the direction of the y-axis. Therefore it's better to use [90 -90]
.
Simple example:
Before swap:
And then after changing the view:
Upvotes: 2
Reputation: 112749
You can directly access the 'XData'
and 'YData'
properties of each plot and swap them:
c = get(gca,'children'); %// get children of axes
for n = 1:numel(children); %// for each children
set(c(n),'XData',get(c(n),'YData'),'YData',get(c(n),'XData')); %// swap XData, YData
end
Upvotes: 1