RATS 11.1
RATS 11.1

Graphics /

Batch Graph Generation

Home Page

← Previous Next →

Generating and saving graphs one at a time can be slow and error-prone if you are producing many of them, or if you have a standard program that you need to run on a regular basis. In such cases, you may prefer to have your program save your graphs automatically. The modern was to do that is with the GSAVE instruction, as described below. OPEN PLOT is a older method which still works. Either way, depending upon what you intend to do with the graphs, you may need to change to "patterns" (that is, black and white) from color:

Color Versus Grayscale

Because you aren’t saving each one manually, you can’t switch them to over to black and white mode if that’s what you need. Instead, use the instruction

 

grparm(patterns)

 

before you generate the graphs if you want them to be drawn in black and white. (You only need to do this once). This changes the default appearance of all types of graphs from color to black and white (patterns).

 

GSAVE(GFORMAT=format)  template

The GSAVE instruction is your best choice for automatically saving multiple graphs into separate files (one graph per file), and for automatically saving files in formats other than RGF, such as PostScript. You just supply a filename “template”, and RATS saves any subsequent graphs using that template plus a sequence number for the filename.

 

The template will usually be a filename string that includes an asterisk (*) symbol. For each graph you generate, RATS will construct a filename by replacing the asterisk with a sequence number, and save the graph using the constructed filename. Omit the asterisk if you want to save a single graph under a specific name.

 

By default, this saves graphs in RGF format. You can use the FORMAT=format option to select other formats. Choices for FORMAT include: RGF, PORTRAIT, LANDSCAPE, PDF, LPDF, WMF, and PNG, where PORTRAIT and LANDSCAPE are PostScript format, saved in portrait and landscape orientations, respectively and LPDF is pdf saved in landscape.

 

The availability of some formats is platform-dependent.

 

The code below graphs a series of impulse response graphs and saves them in a set of PostScript format files named ImpulseResp1.EPS, ImpulseResp2.EPS, and so on.

 

gsave(format=portrait) "ImpulseResp*.eps"

do i=1,neqn

  compute header="Plot of responses of "+implabel(i)

  graph(header=header,key=below,klabels=implabel,number=0,$

     series=%scol(impblk,i)) neqn

end do i

 

GSAVE(NOHEADER/NOFOOTER)

GSAVE also has NOHEADER and NOFOOTER options which can be used to suppress the (outer) header or footer on a graph being saved (either using GSAVE or standard single-file operations). This can be handy if the graph will be inserted into a document which will have its own captioning for the graph. You can keep the header or footer on the graph so it will still be easy to examine while you’re working on it with RATS, but then strip it off when it’s being saved for import into the final document.

 

GSAVE(PATTERNS)

GSAVE has a PATTERNS option which can be used to downgrade graphs to black and white from color, but it does that only when graphs are exported; it does not change the screen appearance the way GRPARM(PATTERNS) does.

 

OPEN PLOT filename

If you issue an OPEN PLOT instruction, any subsequent graphs you generate will be saved to the specified RGF format file, until you either do a CLOSE PLOT instruction, or use another OPEN PLOT instruction to open a different graph file.

 

This works in both interactive and batch modes, and offers the option of saving multiple graphs to a single file.

 

There is no problem with putting several pages of graphics on a single file if you just intend to print them. However, if you are going to reopen the graphs later for viewing or for translation to another format, you should put only one graph on a file. If your program generates several graphs, you can either use a separate OPEN PLOT instruction for each graph as shown below, or use the GSAVE instruction.

 

open plot gdp.rgf

graph(header="US Real GDP")

# gdp90

open plot consump.rgf

graph(header="Consumption of Durable Goods")

# gcd

 

Printing Graphs Automatically

If you want RATS to print graphs automatically, include the instruction

 

environment printgraphs

 

in your program (prior to the graphing instructions). This will spool the graphs to your default printer as they are generated.

 


Copyright © 2026 Thomas A. Doan