# How to plot and print two graphs in a same page?

조회 수: 17 (최근 30일)
ANANTA BIJOY BHADRA 2022년 4월 18일
답변: Richard Quist 2022년 4월 30일
I have been trying two put two graphs in a single make and make it PDF. But the border of the pages is not equal on all the sides and the grpahs are tend to shift. the positions of the graphs are dictated by the 'PaperPosition' command which is applied after the 2nd graph. I need both the grpah on the same page with equal border margin and grpah lengths (height and width). I have added the code for clarification. Is there any way that I can use to solve the problem. The code is given below:
p=1
x=rand(90,1)
subplot(2,1,1)
plot(x)
grid on;
grid minor;
str = sprintf('Random data for experiment');
xlabel({'X-axis',str});
ylabel('Y-axis');
t=0:0.01:4*pi
f=1
y=5*sin(2*pi*f*t)
subplot(2,1,2)
plot(t,y)
grid on;
grid minor
str = sprintf('Sinewave for experiment');
xlabel({'Time(s)',str});
ylabel('Voltage(v)');
x_width1=8.7;
y_width1=11;
set(gcf, 'PaperPosition', [-0.1 0.4 x_width1 y_width1]);
##### 댓글 수: 7이전 댓글 5개 표시이전 댓글 5개 숨기기
+1 @Nikhil Sapre (copy to answers section)
If you're using R2020a or later you could use exportgraphics but the figure borders will be trimmed.
ANANTA BIJOY BHADRA 2022년 4월 20일
Solved the problem by myself. Had to set position and x_width and y_width properly. Used 'saveas' command to save the figures as PDF. Thank you all.

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

### 채택된 답변

Richard Quist 2022년 4월 30일
If you're using R2020a or later, you might want to try the exportgraphics command, which produces tightly cropped output (eliminating excess white space) in most cases. For PDF and other vector output formats (like EPS), you can ensure this by specifying the ContentType parameter:
% In R2020a and later, use the exportgraphics command and specify the 'ContentType' as 'vector':
exportgraphics(fig, 'output.pdf', 'ContentType', 'vector');

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

### 카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by