[G-2] graph export -- Export current graph
Syntax
graph export newfilename.suffix [, options]
options Description
---------------------------------------------------------------------
name(windowname) name of Graph window to export
as(fileformat) desired format of output
replace newfilename may already exist
override_options override defaults in conversion
---------------------------------------------------------------------
If as() is not specified, the output format is determined by the suffix
of newfilename.suffix:
Implied
suffix option Output format
---------------------------------------------------------------------
.ps as(ps) PostScript
.eps as(eps) EPS (Encapsulated PostScript)
.svg as(svg) SVG (Scalable Vector Graphics)
.wmf as(wmf) Windows Metafile
.emf as(emf) Windows Enhanced Metafile
.pdf as(pdf) PDF (Portable Document Format)
.png as(png) PNG (Portable Network Graphics)
.tif as(tif) TIFF (Tagged Image File Format)
other must specify as()
---------------------------------------------------------------------
ps, eps, and svg are available for all versions of Stata; png and tif are
available for all versions of Stata except Stata(console); and wmf
and emf are available only for Stata for Windows.
override_options Description
---------------------------------------------------------------------
ps_options when exporting to ps
eps_options when exporting to eps
svg_options when exporting to svg
tif_options when exporting to tif
png_options when exporting to png
---------------------------------------------------------------------
There are no override_options for the pdf format.
Description
graph export exports to a file the graph displayed in a Graph window.
Options
name(windowname) specifies which window to export from when exporting a
graph. Omitting the name() option exports the topmost graph (Stata
for Unix(GUI) users: see Technical note for Stata for Unix(GUI)
users). The name for a window is displayed inside parentheses in the
window title. For example, if the title for a Graph window is Graph
(MyGraph), the name for the window is MyGraph. If a graph is an asis
or graph7 graph where there is no name in the window title, specify
"" for windowname.
as(fileformat) specifies the file format to which the graph is to be
exported. This option is rarely specified because, by default, graph
export determines the format from the suffix of the file being
created.
replace specifies that it is okay to replace filename.suffix if it
already exists.
override_options modify how the graph is converted. See [G-3]
ps_options, [G-3] eps_options, [G-3] svg_options, [G-3] tif_options,
and [G-3] png_options. See also [G-2] graph set for permanently
setting default values for the override_options.
Remarks
Graphs are exported by displaying them on the screen and then typing
. graph export filename.suffix
Remarks are presented under the following headings:
Exporting the graph displayed in a Graph window
Exporting a graph stored on disk
Exporting a graph stored in memory
If your interest is simply in printing a graph, see [G-2] graph print.
Exporting the graph displayed in a Graph window
There are three ways to export the graph displayed in a Graph window:
1. Right-click on the Graph window, select Save Graph..., and choose
the appropriate Save as type.
2. Select File > Save Graph..., and choose the appropriate Save as
type.
3. Type "graph export filename.suffix" in the Command window. Stata
for Unix(GUI) users should use the name() option if there is more
than one graph displayed to ensure that the correct graph is
exported (see Technical note for Stata for Unix(GUI) users).
All three are equivalent. The advantage of graph export is that you can
include it in do-files:
. graph ... (draw a graph)
. graph export filename.suffix (and export it)
By default, graph export determines the output type by the suffix. If we
wanted to create an Encapsulated PostScript file, we might type
. graph export figure57.eps
Exporting a graph stored on disk
To export a graph stored on disk, type
. graph use gph_filename
. graph export output_filename.suffix
Do not specify graph use's nodraw option; see [G-2] graph use.
Stata(console) for Unix users: follow the instructions just given, even
though you have no Graph window and cannot see what has just been
"displayed". Use the graph, and then export it.
Exporting a graph stored in memory
To export a graph stored in memory but not currently displayed, type
. graph display name
. graph export filename.suffix
Do not specify graph display's nodraw option; see [G-2] graph display.
Stata for Unix(console) users: follow the instructions just given, even
though you have no Graph window and cannot see what has just been
"displayed". Display the graph, and then export it.
Technical note for Stata for Unix(GUI) users
X-Windows does not have a concept of a window z-order, which prevents
Stata from determining which window is the topmost window. Instead,
Stata determines which window is topmost based on which window has the
focus. However, some window managers will set the focus to a window
without bringing the window to the top. What Stata considers the topmost
window to Stata may not appear topmost visually. For this reason, you
should always use the name() option to ensure that the correct Graph
window is exported.