MATLAB figures: Difference between revisions

From Fluids Wiki
Jump to navigation Jump to search
No edit summary
Line 37: Line 37:
== Cropping with pdfcrop ==
== Cropping with pdfcrop ==


Typically, pdf files generated with MATLAB result in a full-page pdf (i.e., your figure + white space). To remove the spurious whitespace, use pdfcrop (available on Mac and Linux machines) in the your operating system's console:
Typically, pdf files generated with MATLAB result in a full-page pdf (i.e., your figure + white space). To remove the spurious whitespace, use pdfcrop (available on Mac and Linux machines) in the your operating system's console.


<syntaxhighlight lang="matlab">
<syntaxhighlight lang="matlab">
pdfcrop uncropped-file.pdf cropped-file.pdf
pdfcrop uncropped-file.pdf cropped-file.pdf
</syntaxhighlight>
</syntaxhighlight>

Revision as of 21:43, 17 May 2011

This page describes the best practices for making figures in MATLAB for inclusion in a LATEX document

Vector graphics

Most of the time you will want to choose vector graphics, that is, use MATLAB's "painters" renderer. Code to select this is:

set(gcf,'renderer','painters');

Set the figure size

Now you need to decide what the side of the figure should be. For a standard LaTeX report, we might want the plot to span the width of the page (ex: 6 inches wide) and half as tall (3 inches). to set 6x3 inch we use

set(gcf, 'PaperUnits', 'inches', 'PaperSize', [6 3]);

Export as PDF

Now you print to a PDF file.

print('-dpdf','filename.pdf');

Inclusion in LaTeX

\begin{figure}
  \centering
  \includegraphics{filename.pdf}
  \caption{Description goes here.}
  \label{label:here}
\end{figure}

Cropping with pdfcrop

Typically, pdf files generated with MATLAB result in a full-page pdf (i.e., your figure + white space). To remove the spurious whitespace, use pdfcrop (available on Mac and Linux machines) in the your operating system's console.

pdfcrop uncropped-file.pdf cropped-file.pdf