Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exchange subplots in figure

I create a figure containing 4 subplots like:

y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
fig = figure
for i = 1 : 4
    h(i) = subplot(1,4,i)
    bar(y)
end

Now I would like to exchange the order of the subplots. For example the first subplot should go in the last column (4th) and the 2nd subplot should exchange with the 3rd.

Is it doable without generating again the figure?

like image 675
gabboshow Avatar asked Mar 14 '23 13:03

gabboshow


1 Answers

Perhaps you could change their 'position' of the axes h. For instance:

% get position
pos = get(h,'position');
% change position, 1st <-> 4th, 2nd <->3rd.
set(h(1),'position',pos{4});
set(h(4),'position',pos{1});
set(h(2),'position',pos{3});
set(h(3),'position',pos{2});
like image 78
MinF Avatar answered Mar 24 '23 15:03

MinF