How can I rotate and reflect subplots as a group?
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
David Goodmanson
2019-8-21
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.
回答(1 个)
Bruno Luong
2019-8-21
编辑:Bruno Luong
2019-8-21


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 个评论
David Goodmanson
2019-8-21
Hi Bruno,
I like the loook of the patterns, but plot(x,y) --> plot(y,x) reflects across the wrong diagonal.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
