Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Everything is all right before I updated all my MiKTeX package to latest version. But after that, I find that all .eps file generated by Matlab cannot be shown correctly.

For example. I use Matlab to plot sin(n)

n = 1:0.1:50;
plot(n, sin(n));

And I got the figure like this.

matlab figure

I use Matlab 2013a(tested in 2011b as well).

I save this figure by File-> Save As...-> test.eps. But when I use LaTeX to generate .pdf file with this piece of code

\documentclass[a4paper]{article}
\usepackage{graphicx}
\begin{document}
test1
\begin{figure}
 \begin{center}
  \includegraphics[height=140mm]{test.eps}
 \end{center}
\end{figure}
test2
\end{document}

I use xelatex to compile my .tex file, and got a pdf like this

.eps shown at wrong position

The .eps file is shown at wrong position. "center" seems to be useless. I have done other tests, which prove that .eps file generated by other software(Word, Adobe Acrobat) can be shown correctly. Therefore, I think the problem may lie in Matlab. Perhaps the .eps file generated by Matlab is not compatible with some tex package.

This subtle problem has wasted me much time. Does anybody know why and how to solve the problem ? Thanks!

share|improve this question
    
Welcome to TeX.SX! You can have a look on our starter guide. Note that instead of \begin{center}...\end{center} you better use \centering. This does not solve your problem, though. –  mafp May 29 '13 at 21:07
    
It's due to the stupid bounding box declaration in the .eps file. Becaue it is matlab being itself. You can open it in GSView and export it again by clicking on its true bounding box. I would use pgfplots for plotting directly for that though. –  percusse May 29 '13 at 21:22
    
2  
Both of @texenthusiast's links mention export_fig which can be found on the MATLAB Central File Exchange website. It fixes many of the problems inherent in MATLAB's rather poor built-in EPS and PDF rendering engines. –  craigim May 29 '13 at 22:48
1  
@texenthusiast I find a solution of matlab2tikz at your links. .tikz file generated by matlab2tikz can be shown correctly. –  user31469 May 30 '13 at 4:56
show 5 more comments

1 Answer

up vote 1 down vote accepted

I will just try to give you a quick push. If I recall correctly \begin{center} puts the center of the coordinate system which is left lower corner of your picture (think of picture being in the first quadrant) at the center of the page. That is exactly what I see on your figure. Did you play with moving things left down etc? I do not have now to check right now but I would be very, very surprised to see that MATLAB doesn't produce correct eps file (that it does not compute correct Bounding Boxes). You can always export figure as PostScript and then use something ps2eps to produce correct Bounding Boxes for those eps files and filters some special postscript command sequences that can produce erroneous results.

share|improve this answer
1  
You can be very very surprised. It's been like that since matlab 6.5 and I've reported it a few times. –  percusse May 29 '13 at 21:23
    
@percusse I would be damned!!! That thing is so expensive! I can not believe. These days I moved almost 100% to Python so I do not use it often. What happen if you export figure in PostScript and then use ps2eps to convert? It might be just those stupid Bounding Boxes. –  Predrag Punosevac May 29 '13 at 21:29
1  
Exactly. I moved to Python too. –  percusse May 29 '13 at 21:29
    
Spyder: Interesting Python IDE similar to MATLAB –  texenthusiast May 29 '13 at 21:38
1  
@percusse I third the move to Python! –  dustin May 29 '13 at 21:41
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.