필터 지우기
필터 지우기

Help with making square and symmetric subplots

조회 수: 2 (최근 30일)
Kyana Shayan
Kyana Shayan 2018년 4월 26일
댓글: xi lin 2020년 1월 9일
Dear all,
I am trying to plot 6 graphs in a single plot using subplot function. I would like them to look in a square shape with same axes lengths. However, this is what I get (see attached figure). I have not made any arrangements in my code on subplots.
The code:
figure(3)
subplot(6,2,1,'align');
title(['Episode: ',int2str(i),' epsilon: ',num2str(epsilon)]);
plot(xpoints,ypoints,'Color',[0,0.7,0.9]);
pbaspect([2 2 1]);
xlabel('r');
ylabel('x');
drawnow
subplot(6,2,2,'align');
plot(xpoints,zpoints, 'Color','r');
pbaspect([1 1 1]);
xlabel('r');
ylabel('y');
drawnow
subplot(6,2,3,'align');
plot(xpoints,lpoints, 'Color','r');
pbaspect([1 1 1]);
xlabel('r');
ylabel('z');
drawnow
subplot(6,2,4,'align');
plot(xpoints,convpoints, 'Color','r');
pbaspect([1 1 1]);
xlabel('r');
ylabel('m');
drawnow
subplot(6,2,5,'align');
plot(xpoints,explore, 'Color','b');
pbaspect([1 1 1]);
xlabel(r');
ylabel('n');
drawnow
subplot(6,2,6,'align');
plot(xpoints,gpoints, 'Color','r');
pbaspect([1 1 1]);
xlabel('r');
ylabel('k');
drawnow
Really appreciate it if someone can help with this.
Kind Regards,
Kyana

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 4월 26일
Try the following code, you can use the Position property of each axis to control its position, width, and height. More Information here.
subplot(321)
subplot(322)
subplot(323)
subplot(324)
subplot(325)
subplot(326)
f = gcf;
f.Units = 'pixels';
f.Position = [100 100 700 700];
for i=f.Children'
i.Position(3:4) = 0.25;
end
You must note that aspect ratio also depends on resizing of the figure window.
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2018년 4월 27일
Try these settings,
f = gcf;
ax = f.Children;
f.Units = 'pixels';
f.Position = [100 100 700 700];
for i=1:length(ax)
if(mod(i, 2) == 1)
ax(i).Position(1:2) = [0.6 0.1+floor((i-1)/2)*0.3];
else
ax(i).Position(1:2) = [0.1 0.1+floor((i-1)/2)*0.3];
end
ax(i).Position(3:4) = 0.23;
end
You may need to experiment with ax(i).Position values because end result also depends on your screen resolution. Your figure looks like this on my screen after these settings.
xi lin
xi lin 2020년 1월 9일
great! this fixed my problem!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by