How can I rotate and reflect subplots as a group?

16 views (last 30 days)
I have plotted a unique shape in each of nine subplots. The entire group of nine needs to be reflected over a vertical axis and then rotated 90 degrees counterclockwise. How can I do this?
I have two ways of thinking about this problem:
1) Completing the reflection and rotation as if the nine subplots together are one image. (Unfortunately, I can't just save them as an image because there are other subplots that I don't want to affect).
2) Reflecting and rotating each subplot individually. The problem with this: I would also need to change the order of subplots. Each shape is drawn as an iteration of a for loop, and I don't know how to make the loop draw the shapes in a different order.
Here's a bit of my code:
for h=1:9
% Begin plotting a subplot (a single matrix)
subplot(p,6,l)
% DM is the matrix for which the six entries in each row
% encode the 6 characteristics of this particular puzzle
f=[
%specifications for the face of the shape%
];
% Patch is a function that plots the shape with face f
patch(f, %line colour, face colour, line width, other specifying info for the shape
)
% Remove the grid from all of the subplots, set an axis
% size, remove the ticks from the axes, put a box around
% each matrix, etc.
grid off
axis([-5,5,-5,5])
set(gca,'YTick',[],'XTick',[]);
set(gca,'LooseInset',get(gca,'TightInset'));
box on
set(groot,'DefaultFigureGraphicsSmoothing','on');
set(gcf, 'renderer', 'opengl');
Thanks very much for any help you can give.
  3 Comments
Frances McCormick
Frances McCormick on 21 Aug 2019
Hi David,
Thank you for your response.
Both the orientation and the position of the plots should change. Here's a visual example: if I were to arrange the numbers 1 through 9 in a grid as follows...
1 2 3
4 5 6
7 8 9
...the final product should look like this image:
illustration.PNG
David Goodmanson
David Goodmanson on 21 Aug 2019
Hi Frances,
Lots of possibilities here. The reflection and rotation that you mention are the same as a reflection of everything, plots and subplot positions, across the main diagonal that runs from upper left to lower right. It sounds like for the individual subplots you have that process covered.
For the position of each subplot, you can keep the do loop basically unchanged and just create an index vector for the new locations. So suppose you are doing something like this:
figure(1)
for k = 1:9
subplot(3,3,k)
(plot stuff that depends on k)
end
It becomes
figure(1)
ind = [1 4 7 2 5 8 3 6 9]
for k = 1:9
subplot(3,3,ind(k))
(plot stuff that depends on k,
except reflected across the main subplot diagonal)
end
so old plot position 2 goes to new plot position 4, etc. There are more sophisticated ways to create the index vector if it were 7x7 or something, but just writing it out works well enough here.

Sign in to comment.

Answers (1)

Bruno Luong
Bruno Luong on 21 Aug 2019
Edited: Bruno Luong on 21 Aug 2019
Normal.png
Flip.png
x = rand(5,9);
y = rand(5,9);
c = rand(5,9);
close all
% Normal
figure
for h=1:9
[m,n] = ind2sub([3 3],h);
k = sub2ind([3 3],m,n);
subplot(3,3,k);
patch(x(:,h),y(:,h),c(:,h));
title(num2str(h));
end
% Flip + rotate
figure
for h=1:9
[m,n] = ind2sub([3 3],h);
k = sub2ind([3 3],n,m);
subplot(3,3,k);
patch(-y(:,h),-x(:,h),c(:,h));
title(num2str(h));
end
  2 Comments
David Goodmanson
David Goodmanson on 21 Aug 2019
Hi Bruno,
I like the loook of the patterns, but plot(x,y) --> plot(y,x) reflects across the wrong diagonal.

Sign in to comment.

Tags

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!