Plots Saved as Different Sizes

조회 수: 4 (최근 30일)
David Mandel
David Mandel 2016년 3월 16일
댓글: John Smith 2023년 8월 22일
I'm creating plots in a loop as below:
x=linspace(-2,2);
for i=1:4
h = figure;
plot(x,normpdf(x,0,1));
filename = sprintf('plot%i.eps',i);
hgexport(h,filename);
end
I am then including them in a LaTeX document using this code:
\documentclass{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.49\textwidth]{plot1}
\includegraphics[width=0.49\textwidth]{plot2}
\includegraphics[width=0.49\textwidth]{plot3}
\includegraphics[width=0.49\textwidth]{plot4}
\end{figure}
\end{document}
The problem is that `plot3.eps` is slightly larger, as seen on the bottom left from the pdf of this LaTeX code:
How can I save plots so that they are all the same sizes? I suspect this is MATLAB's doing and not LaTeX because the MATLAB figure for `plot3` popped up slightly below on my desktop the other figures during the MATLAB run.
  댓글 수: 2
Dave Behera
Dave Behera 2016년 3월 25일
Can you open the .eps files in a different software than MATLAB to check if the dimensions really mismatch?
I was able to run your code in MATLAB and got 4 eps files which were identical in terms of size. Then, I used your latex code to create a latex project on https://www.sharelatex.com. The generated pdf had no alignment issues like you reported.
It most likely is not an issue with MATLAB. You may need to add some changes to your latex code to make it work on your system. But, it works fine as it is on sharelatex.com. Do try it out!
John Smith
John Smith 2023년 8월 22일
I know it's an old post but I bumped into the very same issue, too (Matlab R2022b, Ubuntu). I ran the same Matlab code on two different computers, and I used the same LaTeX code on Overleaf. Running the Matlab code on the first device gave me plots with different sizes when inserted into the LaTeX code, while I got figures of the same size when the code was executed on another device. I don't know the reason behind it, but it may be related to the graphics renderer Matlab uses to create the plots.

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

답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by