Issue Matlab EPS figures - matlab

I have a problem when I create a EPS figure which I want to include in Latex. Somehow I am unable to place a caption above the figure created with Matlab. It gets overwritten by whitespace. I have created a minimum working example. The figure in matlab is created according the following code:
plot(1:10)
title('A line')
print('test','-depsc2')
And the corresponding latex file:
\documentclass[a4paper]{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\caption{Caption is overwritten}
\includegraphics[width=\textwidth]{test.eps}
\end{figure}
\end{document}
No caption is visible in the output pdf. I am a dvi-ps-pdf chain.
It seems to be an issue with the bounding box values. If I add go to the draft mode of graphicx (\usepackage[draft]{graphicx} ) the caption appears.
Thanks for any help.
Best, Rob

Try the clip option in includegraphics:
\includegraphics[width=\textwidth, clip]{test.eps}
You may also want to include some vertical space between caption and figure:
\caption{Caption is overwritten}
\vspace{5mm}
\includegraphics[width=\textwidth, clip]{test.eps}

Related

Saving figure to pdf prints # instead of tabs in titles

if I create a plot with some tabs in the titles and try saving that to a local pdf file (via print function), I get some hashtags instead of tabs in the pdf. This does not occur in the visible figure.
For example, I plotted the residuals of an approximant to the runge function on a grid:
plot(g, f(g) - runge(g));
title(sprintf('residuals,\t max_x(s-f) = %.3f', max(f(g)-runge(g))));
Then after some axes manipulation (grid, boxes, etc..) I execute
h = gcf;
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
print(h,'data/runge_example.pdf','-dpdf','-r200')
close(h)
Is somebody aware of that behaviour or better able to found that as already solved than I am?
EDIT: Same behaviour with saveas and saving to eps. This does not happen with \n
EDIT2: I'm using Matlab Version R2017b (9.3.0.7...)
So, after a long discussion we figured out that we have no idea of how to use tabs in matlab titles in combination with latex mode.
To clarify: use math environments and escape tex directives, otherwise it will throw an error.
so
sprintf('residuals,\t $max_x(\\vert s-f\\vert) = %.3f$', max(f(g)-runge(g))));
will give you a nice string:
residuals, $max_x(\vert s-f\vert) = 0.264$
The problem is, that it really is a tab. And the matlab latex interpreter (don't know which one that uses, the system or an own) crashes on that. I copy-pasted that to a tex document and pdflatex ran fine on it (but not showing that much space unfortunately).
So, I came up with the following fix:
use the latex directive \quad or \qquad:
title(sprintf('residuals,\\quad $max_x(\\vert s-f\\vert) = %.3f$', max(abs(f(g)-runge(g)))));
This will give you more space than a normal space.
EDIT: For this to work you need the interpreter of matlab to be set to "latex" instead of the default "tex". Do this by changing the title to
title(title_string, 'Interpreter', 'latex')
or by setting (globally for that script)
set(groot, 'defaultTextInterpreter', 'latex')

Greek letter \xi issue in Matlab eps print out

When I plot a figure and type greek letter in the title, it looks like
However, when I save the figure as EPS output, the eps file looks like
It's obviously that the Greek letter \xi_p disappears.
Anyone who knows what happened and solutions, please give me a reply.
It would be much grateful.
Best regards,
mike
First I would like to thank KiW for the help.
I found a solution that works with my MATLAB 2014b.
Solution by specifying the interpreter directly in the code
We can set the interpreter-property directly to latex when calling xlabel or title as shamalaima pointed out in a comment:
xlabel('$\xi_{\textrm{p}}$','Interpreter','latex');
title('$\xi_{\textrm{p}}$','Interpreter','latex');
Solution using the property editor
Another way to do it is by using the property editor as follows:
After making the figure, click the white arrow and click the title (or label).
In the Property Editor, change the Interpreter to latex.
After this, choose the Axes. We can now find the title editor in the left bottom side. Just write the title as you do in latex.
Mine would be $\xi_{_\textrm{p}}=1e$-$4a_{_\textrm{ho}}$ in the font of Times New Roman.
It works now in my EPS output.
Using EPS Viewer the symbol is not lost. As you can see in the picture that works perfectly fine. I used:
plot(x,y)
title('\xi _{P}=1e-4a _{ho}')
So I assume it could be a problem of the program you use to open your .EPS file
I think that the best solution is to set the latex interpreter as default:
set(0,'defaulttextinterpreter','latex')
but of course it depends case by case.

Matlab figure saved as .eps appears in 'horizontal sections' when opened in Adobe Illustrator

I normally save my matlab figures as .eps and then make them better looking using Adobe Illustrator. This works for most figures but not all.
For example I plotted my data using the violin.m function from file exchange. When I save it as .eps and open it in Illustrator, I don't get an editable figure as I usually do. Instead, My figure appears chopped in horizontal sections, and all I can do is delete them (like in the figure below).
Is there anything I can do in either matlab or Illustrator to be able to edit the figure?
I don't need an .eps file, I just need to be able to edit it.
EDITS:
I tried #MattSchmatt's suggestion of using the print2eps function but I had the same problem.
Saving as .pdf doesn't solve the problem, because the image I get is not editable in Illustrator (plus, I also get the horizontal 'chunks').
A minimal, complete and verifiable example requires matlab, the violin function linked above and illustrator. But if it helps, here's the matlab code to produce a similar figure. I save by clicking on Figure -> save as. (But as I said above I tried the print2eps function and that was the same).
X = rand(100,6);
figure; violin(X)
I tried the following, didn't work either.
set(gcf, 'Renderer', 'painters')
As the author of the question suggests, I also wasn't able to export an editable (vectorized) .eps file into Illustrator. However, exporting it as .pdf does the trick. The 'fill' for the violin plots is weird, though, and has horizontal sections (perhaps something to do with the way the density estimate is being plotted?) all over. I was able to fix this and make the plots normal (with solid filled shades): select all the horizontal sections/chunks using the magic wand tool, and then increase opacity to 100% (it is set to 50 based on the exported file). Once all the required edits are made, export the file as .tiff and it seems to look fine. Hope this replicates, and thus helps! (my MATLAB version is 2016, and Illustrator version is the CS5)

Matlab border around figure

In attached image the output looks boring to me. Is it possible to have the subplots enclosed in a border?
Note: This question is not specific to publishing only but in general, say for exported images also.
Thanks
Postscript: I actually need this:
You can add a box like in here
making your code:
close all
figure()
padd=0.04
axes('Position',[padd padd 1-padd*2 1-padd*2],'xtick',[],'ytick',[],'box','on','handlevisibility','off')
subplot(1,2,1)
imagesc(magic(2))
subplot(1,2,2)
imagesc(magic(3))
This yields
And you can change the padd to be bigger or smaller
I obtained this just by plotting lines of different thickness 1.
The text was added with Inkscape though.
If I understand correctly what you want to do, you can obtain borders inside a figure using uipanels http://www.mathworks.com/help/matlab/ref/uipanel.html like this:
Code is:
u=uipanel('Title','MainPanel')
u1=uipanel('Parent',u,'BorderType','line','HighlightColor','k','Title','Subpanel 1','Position',[0,0,0.5,1])
u2=uipanel('Parent',u,'BorderType','line','HighlightColor','k','Title','Subpanel 2','Position',[0.5,0,0.5,1])
axes1=axes('Parent',u1)
imagesc(magic(2))
axes2=axes('Parent',u2)
imagesc(magic(3))
Of course you can change border widths, colors, titles and such

Add text to PDF

I've got an exported version of a MATLAB diagram, similar to the one below. The problem is, that there are no axis captions. It's not possible to export the file again from MATLAB. I need to edit the PDF programmatically and edit about 100 diagrams, all with the same axis positions.
Is there a clean and fast way to paste the Strings X and Y at the corresponding positions in the pdf based on a batch process?
Create a PDF file with the captions. Add that as a background with to the PDF files with pdftk.
if know how to use LaTeX, the pstool package can bring you far on this on, including replacing labels (or actually any text on an eps figure) with TeX symbolic expressions. Neat if you're already working in LaTeX.