Why do all text in figures move when saving as eps?

xlabels move to the left, ylabels move down, titles move to the left. If I use, for example:
text(0.5,0.95,'12 V','units','normalized','horizontalalignment','center')
then '12 V' will appear centered in the plot, near the top, as it should. After saving, however, it will have shifted slightly to the left.
Perhaps the "center" is recalculated as the center of the entire figure rather than just the center of the plot. (EDIT: This cannot be entirely true because the longer the text is, the more it moves.)
I have tried saving with print(gcf,'-depsc','figname') and hgexport(gcf,'figname') as well as just using the Export option in the Plot Tools window, but in all cases the same thing happens.
I read somewhere that there is a bug with the legends if you use set PaperPosition, because it changes the PaperPositionMode from auto to manual. I have tried setting it to auto and I have tried restarting Matlab and saving figures without ever setting the PaperPosition, since apparently 'auto' should be the default mode. Still, the same thing happens.
The attached figure shows an example generated with the command sequence:
>> plot([1 2], [1 2])
>> grid on
>> text(0.5,0.95,'test text test text','units','normalized','HorizontalAlignment','center')
>> title('test title test title test title')
>> xlabel('xlabel (units)')
>> ylabel('ylabel (units)')
>> legend('legend','location','northwest')
and exported from the Plot Tools window.
This is all when I save the figures as eps files. The problem does not arise if I use png instead.
The Matlab version I use is R2018a for Linux (64-bit Debian).
EDIT: I don't get this problem using SVG instead of EPS. However, I've seen people saying "SVG was designed for the web while EPS is intended for print" and I'm working on something that's not for the web but will be printed. Also, I'm using LaTeX which does not natively support SVG.

6 commentaires

Where are you intending to use the eps file? Also, can you try a different viewer, it may be a problem with the way your viewer is rendering the eps file.

et11mpn
et11mpn le 24 Avr 2018
Modifié(e) : et11mpn le 24 Avr 2018
Thank you for your response!
I intend to use them in a scientific repport, like an article. They are mostly plots.
I'm writing it in latex and compiling the tex document using "pdflatex filename.tex" or "xelatex filename.tex". In both cases the error is seen in the resulting pdf document.
I have tried opening the eps files in Gwenview and Ocular. In both cases the text is displaced as described.
Unfortunately eps files cannot be uploaded here, otherwise I would have attached it to the original post.

Although this is not a direct solution to this question, but one solution for you is to use psfrag package in latex. You can directly make changes to eps figure from inside latex file. In your case, you can add the following line to your figure environment before \includegraphics

\psfrag{test text test text}[c][c][1]{\hspace{0.2cm} Write this text now}

Here first {} should contain exact string as presnt in you eps figure. [c][c] is used to specify the alignment text with the original text. Next [1] is used to specify the scale of font, 1 means font will be same as the paragraph text in the latex document. The last {} is used to specify the replacement text. You can try different values of \hspace{} until you get desired alignment.

et11mpn
et11mpn le 25 Avr 2018
Ok, thanks for you help! I'll try playing around with that. It could definitely be useful, although for the axes labels and axes tick labels I really want the Matlab standard.
So do you think it's the eps file or the compilation of it? Could I send you the eps file somehow?
If you have some doubt about the rendering of eps on Linux, you can try an online viewer. It might be some bug with the MATLAB on Debian.
et11mpn
et11mpn le 27 Avr 2018
Thanks again! The online viewer showed the same problem, so ye it's probably because I'm using Debian.

Connectez-vous pour commenter.

Réponses (1)

phnerd
phnerd le 12 Avr 2018

0 votes

this figure can be saved as emf. what's the different between this two kinds of format?

1 commentaire

et11mpn
et11mpn le 12 Avr 2018
They're both vector graphics so it would probably look just as good, and maybe there's no text displacement, but I can't use it since I'm on Linux. Wmf and emf seem to be Windows exclusives.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Printing and Saving dans Centre d'aide et File Exchange

Produits

Question posée :

le 12 Avr 2018

Modifié(e) :

le 5 Juin 2018

Community Treasure Hunt

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

Start Hunting!

Translated by