<html lang="en"> <head> <title>Printing and Saving Plots - GNU Octave</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Octave"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="High_002dLevel-Plotting.html#High_002dLevel-Plotting" title="High-Level Plotting"> <link rel="prev" href="Multiple-Plot-Windows.html#Multiple-Plot-Windows" title="Multiple Plot Windows"> <link rel="next" href="Interacting-with-Plots.html#Interacting-with-Plots" title="Interacting with Plots"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Printing-and-Saving-Plots"></a> <p> Next: <a rel="next" accesskey="n" href="Interacting-with-Plots.html#Interacting-with-Plots">Interacting with Plots</a>, Previous: <a rel="previous" accesskey="p" href="Multiple-Plot-Windows.html#Multiple-Plot-Windows">Multiple Plot Windows</a>, Up: <a rel="up" accesskey="u" href="High_002dLevel-Plotting.html#High_002dLevel-Plotting">High-Level Plotting</a> <hr> </div> <h4 class="subsection">15.2.9 Printing and Saving Plots</h4> <p><a name="index-printing-plots-1463"></a><a name="index-saving-plots-1464"></a> The <code>print</code> command allows you to save plots in a variety of formats. For example, <pre class="example"> print -deps foo.eps </pre> <p class="noindent">writes the current figure to an encapsulated PostScript file called <samp><span class="file">foo.eps</span></samp>. <!-- print scripts/plot/print.m --> <p><a name="doc_002dprint"></a> <div class="defun"> — Function File: <b>print</b> ()<var><a name="index-print-1465"></a></var><br> — Function File: <b>print</b> (<var>options</var>)<var><a name="index-print-1466"></a></var><br> — Function File: <b>print</b> (<var>filename, options</var>)<var><a name="index-print-1467"></a></var><br> — Function File: <b>print</b> (<var>h, filename, options</var>)<var><a name="index-print-1468"></a></var><br> <blockquote><p>Print a graph, or save it to a file <p><var>filename</var> defines the file name of the output file. If the file name has no suffix, one is inferred from the specified device and appended to the file name. If no filename is specified, the output is sent to the printer. <p><var>h</var> specifies the figure handle. If no handle is specified the handle for the current figure is used. <p><var>options</var>: <dl> <dt><code>-f</code><var>h</var><dd> Specify the handle, <var>h</var>, of the figure to be printed. The default is the current figure. <br><dt><code>-P</code><var>printer</var><dd> Set the <var>printer</var> name to which the graph is sent if no <var>filename</var> is specified. <br><dt><code>-G</code><var>ghostscript_command</var><dd> Specify the command for calling Ghostscript. For Unix and Windows, the defaults are 'gs' and 'gswin32c', respectively. <br><dt><code>-color</code><dt><code>-mono</code><dd> Monochrome or color output. <br><dt><code>-solid</code><dt><code>-dashed</code><dd> Forces all lines to be solid or dashed, respectively. <br><dt><code>-portrait</code><dt><code>-landscape</code><dd> Specify the orientation of the plot for printed output. For non-printed output the aspect ratio of the output corresponds to the plot area defined by the "paperposition" property in the orientation specified. This options is equivalent to changing the figure's "paperorientation" property. <br><dt><code>-d</code><var>device</var><dd> Output device, where <var>device</var> is one of: <dl> <dt><code>ps</code><dt><code>ps2</code><dt><code>psc</code><dt><code>psc2</code><dd> Postscript (level 1 and 2, mono and color). The FLTK graphics toolkit generates Postscript level 3.0. <br><dt><code>eps</code><dt><code>eps2</code><dt><code>epsc</code><dt><code>epsc2</code><dd> Encapsulated postscript (level 1 and 2, mono and color). The FLTK graphic toolkit generates Postscript level 3.0. <br><dt><code>tex</code><dt><code>epslatex</code><dt><code>epslatexstandalone</code><dt><code>pstex</code><dt><code>pslatex</code><dt><code>pdflatex</code><dd> Generate a LaTeX (or TeX) file for labels, and eps/ps/pdf for graphics. The file produced by <code>epslatexstandalone</code> can be processed directly by LaTeX. The other formats are intended to be included in a LaTeX (or TeX) document. The <code>tex</code> device is the same as the <code>epslatex</code> device. The <code>pdflatex</code> device is only available for the FLTK graphics toolkit. <br><dt><code>tikz</code><dd> Generate a LaTeX file using PGF/TikZ. For the FLTK the result is PGF. <br><dt><code>ill</code><dt><code>aifm</code><dd> Adobe Illustrator (Obsolete for Gnuplot versions > 4.2) <br><dt><code>cdr</code><dt><code>corel</code><dd> CorelDraw <br><dt><code>dxf</code><dd> AutoCAD <br><dt><code>emf</code><dt><code>meta</code><dd> Microsoft Enhanced Metafile <br><dt><code>fig</code><dd> XFig. For the Gnuplot graphics toolkit, the additional options <samp><span class="option">-textspecial</span></samp> or <samp><span class="option">-textnormal</span></samp> can be used to control whether the special flag should be set for the text in the figure (default is <samp><span class="option">-textnormal</span></samp>). <br><dt><code>hpgl</code><dd> HP plotter language <br><dt><code>mf</code><dd> Metafont <br><dt><code>png</code><dd> Portable network graphics <br><dt><code>jpg</code><dt><code>jpeg</code><dd> JPEG image <br><dt><code>gif</code><dd> GIF image (only available for the Gnuplot graphics toolkit) <br><dt><code>pbm</code><dd> PBMplus <br><dt><code>svg</code><dd> Scalable vector graphics <br><dt><code>pdf</code><dd> Portable document format </dl> <p>If the device is omitted, it is inferred from the file extension, or if there is no filename it is sent to the printer as postscript. <br><dt><code>-d</code><var>ghostscript_device</var><dd> Additional devices are supported by Ghostscript. Some examples are; <dl> <dt><code>ljet2p</code><dd> HP LaserJet IIP <br><dt><code>ljet3</code><dd> HP LaserJet III <br><dt><code>deskjet</code><dd> HP DeskJet and DeskJet Plus <br><dt><code>cdj550</code><dd> HP DeskJet 550C <br><dt><code>paintjet</code><dd> HP PointJet <br><dt><code>pcx24b</code><dd> 24-bit color PCX file format <br><dt><code>ppm</code><dd> Portable Pixel Map file format <br><dt><code>pdfwrite</code><dd> Produces pdf output from eps </dl> <p>For a complete list, type `system ("gs -h")' to see what formats and devices are available. <p>When Ghostscript output is sent to a printer the size is determined by the figure's "papersize" property. When the output is sent to a file the size is determined by the plot box defined by the figure's "paperposition" property. <dt><code>-append</code><dd> Appends the PS, or PDF output to a pre-existing file of the same type. <dt><code>-r</code><var>NUM</var><dd> Resolution of bitmaps in pixels per inch. For both metafiles and SVG the default is the screen resolution, for other it is 150 dpi. To specify screen resolution, use "-r0". <br><dt><code>-tight</code><dd> Forces a tight bounding box for eps-files. <br><dt><code>-</code><var>preview</var><dd> Adds a preview to eps-files. Supported formats are; <dl> <dt><code>-interchange</code><dd> Provides an interchange preview. <br><dt><code>-metalfile</code><dd> Provides a metafile preview. <br><dt><code>-pict</code><dd> Provides pict preview. <br><dt><code>-tiff</code><dd> Provides a tiff preview. </dl> <br><dt><code>-S</code><var>xsize</var><code>,</code><var>ysize</var><dd> Plot size in pixels for EMF, GIF, JPEG, PBM, PNG and SVG. For PS, EPS, PDF, and other vector formats the plot size is in points. This option is equivalent to changing the size of the plot box associated with "paperposition" property. Using the command form of the print function, you must quote the <var>xsize</var>,<var>ysize</var> option. For example, by writing <code>"-S640,480"</code><!-- /@w -->. <br><dt><code>-F</code><var>fontname</var><dt><code>-F</code><var>fontname</var><code>:</code><var>size</var><dt><code>-F:</code><var>size</var><dd> Associates all text with the <var>fontname</var> and/or <var>fontsize</var>. <var>fontname</var> is ignored for some devices; dxf, fig, hpgl, etc. </dl> <p>The filename and options can be given in any order. <p>Example: Print to a file, using the svg device. <pre class="example"> figure (1); clf (); surf (peaks); print -dsvg figure1.svg </pre> <p>Example: Print to an HP Deskjet 550C. <pre class="example"> figure (1); clf (); surf (peaks); print -dcdj550 </pre> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dfigure.html#doc_002dfigure">figure</a>, <a href="doc_002dorient.html#doc_002dorient">orient</a>, <a href="doc_002dsaveas.html#doc_002dsaveas">saveas</a>. </p></blockquote></div> <!-- saveas scripts/plot/saveas.m --> <p><a name="doc_002dsaveas"></a> <div class="defun"> — Function File: <b>saveas</b> (<var>h, filename</var>)<var><a name="index-saveas-1469"></a></var><br> — Function File: <b>saveas</b> (<var>h, filename, fmt</var>)<var><a name="index-saveas-1470"></a></var><br> <blockquote><p>Save graphic object <var>h</var> to the file <var>filename</var> in graphic format <var>fmt</var>. <p><var>fmt</var> should be one of the following formats: <dl> <dt><code>ps</code><dd> Postscript <br><dt><code>eps</code><dd> Encapsulated Postscript <br><dt><code>jpg</code><dd> JPEG Image <br><dt><code>png</code><dd> PNG Image <br><dt><code>emf</code><dd> Enhanced Meta File <br><dt><code>pdf</code><dd> Portable Document Format </dl> <p>All device formats specified in <code>print</code> may also be used. If <var>fmt</var> is omitted it is extracted from the extension of <var>filename</var>. The default format is <code>"pdf"</code>. <pre class="example"> clf (); surf (peaks); saveas (1, "figure1.png"); </pre> <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dprint.html#doc_002dprint">print</a>. </p></blockquote></div> <!-- orient scripts/plot/orient.m --> <p><a name="doc_002dorient"></a> <div class="defun"> — Function File: <b>orient</b> (<var>orientation</var>)<var><a name="index-orient-1471"></a></var><br> <blockquote><p>Set the default print orientation. Valid values for <var>orientation</var> include <code>"landscape"</code>, <code>"portrait"</code>, and <code>"tall"</code>. <p>The <code>"tall"</code> option sets the orientation to portait and fills the page with the plot, while leaving a 0.25in border. <p>If called with no arguments, return the default print orientation. </p></blockquote></div> </body></html>