# How to use the PLOT keyword in ZPL

By using the PLOT keyword it is possible to create bespoje analysis plots of practically any data that can be computed by OpticStudio. In this article, we will present a ZPL macro that features the PLOT keyword. This macro works in conjunction with a sample file and will output a figure that plots Optical Path Length. The code and output are provided.

## Introduction

The PLOT keyword allows the user to easily create 2D plots of numeric data. This keyword supports a number of arguments which provide a wide range of options when generating graphics, such as the ability to add axis labels, control tick mark locations, etc. In this article, a ZPL macro featuring the PLOT keyword is shown and explained.

## Using the PLOT keyword in ZPL

The PLOT keyword allows the user to easily create 2D plots of numeric data. This keyword supports a number of arguments which provide a wide range of options when generating graphics, such as the ability to add axis labels, control tick mark locations, etc.

An example macro utilizing the PLOT keyword is provided with the default OpticStudio installation (PLOT_TEST.ZPL). This macro goes with the Cooke 40 degree triplet example located in the directory {Zemax}\Samples\Sequential\Objectives\Cooke 40 degree field.zmx. In this macro, the OPD and optical path length for a ray launched from on-axis field point is calculated for a range of pupil coordinates using the RAYTRACE keyword and the numeric functions OPDC and OPTH:

! This macro is intended to test out the new PLOT keyword ! for ZPL. The calculations are meant to work with the ! sample file Cooke 40 degree field.zmx located in the ! \Zemax\Samples\Sequential\Objectives\ directory. ! ! Written by S. Gangadhara, 12/12/07 !

! Determine number of surfaces in the system

n_surf = NSUR()

! Define array variables to be plotted

DECLARE x1, DOUBLE, 1, 21        # Variables to store DECLARE y1, DOUBLE, 1, 21        #  OPD data DECLARE X2, DOUBLE, 1, n_surf    # Variables to store DECLARE y2, DOUBLE, 1, n_surf    #  OPL data

! Compute array variables using RAYTRACE, OPDC and OPTH

FOR i, 1, 21, 1

x1(i) = 0.1*i-1.1 RAYTRACE 0, 0, 0, 0.1*i-1.1, 1 y1(i) = OPDC()

NEXT i

FOR i, 1, n_surf, 1

x2(i) = (i - 3.0)/2.0 RAYTRACE 0, 0, 0, 0.1*i-1.1, 1 y2(i) = OPTH(i)/50. - 2.0

NEXT i

The variables x1 and y1 store the pupil coordinate and the OPD data for the on-axis field point, respectively. The variables x2 and y2 store the relative surface number and the optical path length (OPL) data for the on-axis field point, respectively. The x2 and y2 data are scaled so that they can be plotted on the same graphical display as x1 and y1. More information on the RAYTRACE keyword and the functions OPDC and OPTH may be found in the Help System at The Programming Tab...About the ZPL.

The results are then plotted to a graphical window using the PLOT keyword:

! Plot results to the screen using PLOT keywords

title$= "PLOT TEST WITH COOKE 40 DEGREE FIELD" xtitle$ = "PUPIL COORDINATE / RELATIVE SURFACE NUMBER"

ytitle$= "WAVES / LENGTH" banner$ = "RESULTS GENERATED USING PLOT_TEST.ZPL"

comment1$= "DATA FOR OPD ARE EXACT" comment2$ = "DATA FOR OPTICAL PATH LENGTH (OPL) ARE NORMALIZED"

comment3$= "X-AXIS FOR OPL DATA IS 0.5*(SURFACE NUMBER - 2)" comment4$ = "Y-AXIS FOR OPL DATA IS LENGTH/50 - 2"

comment5$= "NORMALIZATION OF THE OPL DATA WAS PERFORMED SO THAT IT" comment6$ = "  COULD BE PLOTTED ON THE SAME GRAPH AS THE OPD DATA"

label1$= "OPD FOR ON-AXIS FIELD POINT" label2$ = "OPTICAL PATH LENGTH (OPL)"

x_min = -2.0

y_min = -2.0

x_max = 2.0

y_max = 0.0

x_chk = 0.005

y_chk = 0.005

x_tick = 0.5

y_tick = 0.4

x_form$= "%4.2f" y_form$ = "%4.2f"

xl1 = 0.1

yl1 = 0.6

xl2 = 0.8

yl2 = 0.6

xl3 = 0.45

yl3 = 0.3

xl4 = 0.45

yl4 = 0.9

xlb1 = 0.15

xlb2 = 0.30

ylb1 = 0.65

ylb2 = 0.35

ang1 = 0

ang2 = 15

scl = 1

PLOT NEW

PLOT TITLE, title$ PLOT TITLEX, xtitle$

PLOT TITLEY, ytitle$ PLOT BANNER, banner$

PLOT COMM1, comment1$ PLOT COMM2, comment2$

PLOT COMM3, comment3$ PLOT COMM4, comment4$

PLOT COMM5, comment5$ PLOT COMM6, comment6$

PLOT RANGEX, x_min, x_max

PLOT RANGEY, y_min, y_max

PLOT CHECK, x_chk, y_chk

PLOT TICK, x_tick, y_tick

PLOT FORMATX, x_form$ PLOT FORMATY, y_form$

PLOT DATA, x1, y1, 21, 1, 1, 1

PLOT DATA, x2, y2, n_surf, 3, 2, 0

PLOT LINE, xl1, yl1, xl2, yl2

PLOT LINE, xl3, yl3, xl4, yl4

PLOT LABEL, xlb1, ylb1, ang1, scl, label1$ PLOT LABEL, xlb2, ylb2, ang2, scl, label2$

PLOT GO

In the first section, variables are defined for the numerous plotting options, such as the plot title (title$), plot axes labels (xtitle$ and ytitle\$), plot range (x_min, y_min, x_max, and y_max), etc. A number of PLOT keywords are then issued to plot the results in a graphical display window, with the corresponding title, axes labels, range, etc. Comments are provided in the macro for each of the PLOT keywords (those comments have been omitted from this article for display purposes), and a full description of the various PLOT commands may be found the Help System: The Programming Tab...About the ZPL...KEYWORDS (about the ZPL)...PLOT. The resulting graphical output is:

As you can see, the PLOT keyword provides the user a simple way to generate graphical displays of numeric data in OpticStudio.

KA-01462