Problem; Solution; Setup And Scaling; The Axes And Their Labels - HP 7470A Interfacing And Programming Manual

Graphic plotter
Hide thumbs Also See for HP 7470A:
Table of Contents

Advertisement

"Problem
)
Scale, draw, and label an X- and Y-axis in user units and plot 1981
)
ocaie, u r a w , aiiu lauei a n A- aiiu i-axis 111 usei uuius a i m pioi it»oi
s ^
sales by sales region. Use a different line type for each sales region and
pB"
1
^m
place a legend on the graph. The complete program is in the Listing
■ )
section, following the Solution section.
Solution
^etup and Scaling
£>
*if
)
The first step is to set the plotter to known conditions, cancelling any
\
parameters which may have been set in the previously run program,
jpsa
— — .
'
The IN or DF instruction may be used; IN resets PI and P2; DF does
fc
9
' J ]
j
not. IN is used here.
")
Next, a pen is selected (SPl) and the scaling for this plot is established.
E r m ^ J
The parameters of the IP command determine the location of the scaling
-^^Sj
points, PI and P2. In this graph, all data will be plotted within this
\
P1.P2 area. The points have been chosen to allow room for labels, titles,
C < " . F~3)
and margins outside the P1.P2 rectangle. The scaling statement
'
"^"1
J
SC 1,12,0,150; assigns user unit values to the scaling points. Since we
are plotting one year's sales by month, we have scaled the X-axis
(commonly representing time) from 1 to 12. The Y-axis is scaled in
j
thousands from 0 to 150 so all sales data fall well inside the scaled
>.
area.
You will either need to know the range of your data or be willing to go
through some trial plots with different scales to determine what your
scale statement should be. This graph is scaled from 0 to 150, not 0 to
150 000 — the actual range of sales dollars. There are two reasons for
J
this. First, the largest number accepted by the plotter is 32 767; our
~\
numbers are too large so we need to divide all data by at least 10. In
)
3
this program, both labels and data will be stated in thousands. It is
)
easier to interpret a scale marked with short labels. The eye need only
-v
read a maximum of three characters (150) instead of six (150 000).
)
Thousands or millions of dollars are common scales for graphs.
/
Having established our scaling, we shall draw a frame for the data
•\
area. This is done by moving to the point 1,0 with the pen up, lowering
the pen and drawing to the four corners 12,0; 12,150; 1,150; and 1,0.
J
The coordinates are interpreted as absolute (instead of relative) moves
C j |
•^
since absolute plotting is established by the IN command. The first
three program lines with HP-GL commands are:
'
20 PRINT
" I N ; S P 1 ; I P 1 2 5 0 , 7 5 0 , 9 2 5 0 , 6 2 5 0 ; "
)
3 0 PRINT
" $ C 1 , 1 2 , 0 , 1 5 0 ; "
;
40 PRINT " P U 1 , 0 PD 1 2 , 0 , 1 2 , 1 5 0 , 1 , 1 5 0 , 1 , 0 PU"
)
)
S-2
PUTTING THE COMMANDS TO WORK
)
NOTE: If compatibility with other HP plotters is desired, PA should be
used to begin plotting, and raising and lowering the pen should be
controlled with separate PU and PD commands. In addition, the
stricter syntax of other plotters would be required. ■
The Axes and Their Labels
We are now ready to draw and label the axes. The label size is set by
the absolute size command SI .2 , .3 ; . This creates characters which
are slightly larger than characters of default character size specified by
the IN command. The tick length is established by the tick length com­
mand TL 1.5,0. The resulting ticks will be 1.5% of the horizontal or
vertical distances between the scaling points. No negative portion of
the tick will be drawn; ticks will be entirely above the X-axis and to the
right of the Y-axis.
Axes are commonly drawn using a loop; this program in BASIC uses
FOR...NEXT loops. First, we shall draw the X-axis. Let X range from 1
to 12 representing the 12 months for which we have data. In the loop
we will do four things: move to the integer location on the axis, draw a
tick mark, position the pen below the axis, and draw the label. Note
that the X-parameter of the plot command is a variable. You will need
to know how to send a variable between strings of fixed characters.
The method will differ from computer to computer; consult your com­
puter's documentation and Plotting with Variables in Chapter 3 of this
manual. If you have an HP-IB or HP-IL plotter, refer also to Sending
and Receiving Data in Chapter 9 or 11. The XT instruction draws a
tick, whether the pen is up or down. The pen is up here so we do not
draw the axis line again. You might want to use PD, drawing over the
frame line if your want your axis line a bit darker, or you might w a n t
to redraw the axis again later with a wide pen.
There are several techniques used here to draw the alphabetic labels.
First, so we can use a looping technique, we have placed the labels in a
data statement. (At some point, you might want to access data for the
latest 12 months. If your data were stored together with a date code,
you could use a similar technique to read the label and data from some
file and properly label your graph for the data you were then plotting.)
Secondly, we have used the CP instruction together with BASIC for­
matting (using semicolons to suppress extra characters between print
fields) to center the label under the tick. The base of the tick mark is the
pen position after the tick is drawn. By moving one-third character
space back and one line down, the single character label is centered
under the tick with enough space so it can be easily read. Finally, the
axis title, CALENDAR MONTH, is centered and drawn under the axis.
PUTTING THE COMMANDS TO WORK
8-3

Advertisement

Table of Contents
loading

Table of Contents