Re: Legends for curves in autograph

From: Dave Kennison (kennison@XXXXXX)
Date: Tue Aug 13 1996 - 11:53:32 MDT


        
Percy Selorio wrote:

> I am doing an XY plot using EZMXY routine of autograph. I have
> successfully used different colors for my curves. Is there a way for
> me to create a legend for the different colors of the curves?

Percy,
        
Unfortunately, AUTOGRAPH has no built-in way to do this, but it is not
too difficult to write a quick-and-dirty version.

I have attached a program showing one way to construct such a legend
(with thanks to Ken Hansen for providing the starting point).

I hope this will be of some use to you.

Dave Kennison

P.S. Another way to do this, in version 4, is to use the HLUs and construct
an "XYPlot" object, but I am not so familiar with that approach.

-----

Program follows:

      PROGRAM LEGEND
C
C Declare arrays to hold data defining four different curves.
C
        DIMENSION XDRA(100),YDRA(100,4)
C
C Declare an array to hold four different dash patterns.
C
        DIMENSION IDSH(4)
C
C Define the dash patterns:
C
C 65535 (base 10) = 1111111111111111 (base 2)
C 61680 (base 10) = 1111000011110000 (base 2)
C 52428 (base 10) = 1100110011001100 (base 2)
C 18724 (base 10) = 0100100100100100 (base 2)
C
C (Each 1 bit represents a line segment and each 0 bit a gap.)
C
        DATA IDSH / 65535 , 61680 , 52428 , 18724 /
C
C Define the data for the four different curves.
C
        DO 101 I = 1,100
          XDRA(I) = REAL(I)
          YDRA(I,1) = 20.*10.**(-REAL(I)/20.)
          YDRA(I,2) = 20.*10.**(-REAL(I)/40.)
          YDRA(I,3) = 20.*10.**(-REAL(I)/60.)
          YDRA(I,4) = 20.*10.**(-REAL(I)/80.)
  101 CONTINUE
C
C Open GKS.
C
        CALL OPNGKS
C
C Define some colors to use.
C
        CALL GSCR (1,0,0.00,0.00,0.00) ! black (background)
        CALL GSCR (1,1,1.00,1.00,1.00) ! white (principal foreground)
        CALL GSCR (1,2,1.00,0.00,1.00) ! cyan
        CALL GSCR (1,3,1.00,0.50,0.00) ! orange
        CALL GSCR (1,4,0.00,1.00,0.00) ! green
        CALL GSCR (1,5,0.20,0.56,0.80) ! sky blue
C
C Suppress the frame advance by the AUTOGRAPH routine EZMXY.
C
        CALL AGSETI ('FRAME.',2)
C
C Redefine the graph window (within the plotter frame), moving it up to
C allow room for the legend at the bottom. (This is the window in which
C the entire plot must fit.)
C
        CALL AGSETR ('GRAPH/LEFT. ',0.00)
        CALL AGSETR ('GRAPH/RIGHT. ',1.00)
        CALL AGSETR ('GRAPH/BOTTOM.',0.10)
        CALL AGSETR ('GRAPH/TOP. ',0.98)
C
C Redefine the grid window (within the graph window) to leave a little
C less space than normal at the bottom. (This is the window in which
C the grid must fit. Grid labels go in the space outside the grid
C window, but inside the graph window.)
C
        CALL AGSETR ('GRID/LEFT. ',0.15)
        CALL AGSETR ('GRID/RIGHT. ',0.95)
        CALL AGSETR ('GRID/BOTTOM.',0.10)
        CALL AGSETR ('GRID/TOP. ',0.95)
C
C Define the top label (a label for the whole graph).
C
        CALL AGSETC ('LABEL/NAME.','T')
        CALL AGSETI ('LINE/NUMBER.',100)
        CALL AGSETR ('LINE/CHARACTER SIZE.',.025)
        CALL AGSETC ('LINE/TEXT.','Fruit Ripening Time vs. Temperature')
C
C Define the bottom label (a label for the X axis).
C
        CALL AGSETC ('LABEL/NAME.','B')
        CALL AGSETI ('LINE/NUMBER.',-100)
        CALL AGSETF ('LINE/CHARACTER SIZE.',.020)
        CALL AGSETC ('LINE/TEXT.','Temperature (C:S1::KRU1:O )')
C
C Define the left label (a label for the Y axis).
C
        CALL AGSETC ('LABEL/NAME.','L')
        CALL AGSETI ('LINE/NUMBER.',100)
        CALL AGSETF ('LINE/CHARACTER SIZE.',.020)
        CALL AGSETC ('LINE/TEXT.','Ripening time (hours)')
C
C Define the dash patterns to be used by AUTOGRAPH.
C
        CALL AGSETI ('DASH/SELECTOR.',4)
C
        CALL AGSETI ('DASH/PATTERNS/1.',IDSH(1))
        CALL AGSETI ('DASH/PATTERNS/2.',IDSH(2))
        CALL AGSETI ('DASH/PATTERNS/3.',IDSH(3))
        CALL AGSETI ('DASH/PATTERNS/4.',IDSH(4))
C
C Draw the curves. Color setting is done in the user-callback routine
C AGCHCU. Note that the argument "CHAR(0)" says "don't change the top
C label" (because we defined it above).
C
        CALL EZMXY (XDRA,YDRA,100,4,100,CHAR(0))
C
C Draw the legend. First, SET is called in such a way that we can use
C fractional coordinates.
C
        CALL SET (0.,1.,0.,1.,0.,1.,0.,1.,1)
C
        CALL SFLUSH
        CALL GSPLCI (2)
        CALL PLCHHQ (.65,.026,':U1:APPLES', .012,0.,-1.)
        CALL DASHDB (IDSH(1))
        CALL SFLUSH
        CALL GSLWSC (2.)
        CALL LINED (.75,.026,.95,.026)
        CALL SFLUSH
        CALL GSLWSC (1.)
C
        CALL SFLUSH
        CALL GSPLCI (3)
        CALL PLCHHQ (.65,.051,':U1:ORANGES',.012,0.,-1.)
        CALL DASHDB (IDSH(2))
        CALL SFLUSH
        CALL GSLWSC (2.)
        CALL LINED (.75,.051,.95,.051)
        CALL SFLUSH
        CALL GSLWSC (1.)
C
        CALL SFLUSH
        CALL GSPLCI (4)
        CALL PLCHHQ (.65,.076,':U1:GRAPES', .012,0.,-1.)
        CALL DASHDB (IDSH(3))
        CALL SFLUSH
        CALL GSLWSC (2.)
        CALL LINED (.75,.076,.95,.076)
        CALL SFLUSH
        CALL GSLWSC (1.)
C
        CALL SFLUSH
        CALL GSPLCI (5)
        CALL PLCHHQ (.65,.101,':U1:PEARS', .012,0.,-1.)
        CALL DASHDB (IDSH(4))
        CALL SFLUSH
        CALL GSLWSC (2.)
        CALL LINED (.75,.101,.95,.101)
        CALL SFLUSH
        CALL GSLWSC (1.)
C
C Advance the frame.
C
        CALL FRAME
C
C Close GKS.
C
        CALL CLSGKS
C
C Done.
C
        STOP
C
      END

      SUBROUTINE AGPWRT (XPOS,YPOS,CHRS,NCHS,ISIZ,IORI,ICEN)
C
        CHARACTER*(*) CHRS
C
C This version of AGPWRT replaces the default one in AUTOGRAPH. The
C character strings are drawn using PLCHHQ.
C
C Save the current value of PLOTCHAR's "constant-spacing" flag for
C later restoration.
C
        CALL PCGETR ('CS - CONSTANT SPACING FLAG', CSFL)
C
C If ICEN is non-zero, the character string being drawn is probably
C a numeric label; it looks better to draw these with the "constant-
C spacing" flag set. Otherwise, one of the axis labels is probably
C being drawn and we draw it with variable spacing.
C
        IF (ICEN.NE.0) THEN
          CALL PCSETR ('CS - CONSTANT SPACING FLAG',1.25)
        ELSE
          CALL PCSETR ('CS - CONSTANT SPACING FLAG',0.00)
        ENDIF
C
C Draw the character string using PLCHHQ.
C
        CALL PLCHHQ (XPOS,YPOS,CHRS(1:NCHS),
     + .8*REAL(ISIZ),REAL(IORI),REAL(ICEN))
C
C Reset PLOTCHAR's "constant-spacing" flag to its original value.
C
        CALL PCSETR ('CS - CONSTANT SPACING FLAG', CSFL)
C
C Done.
C
        RETURN
C
      END

      SUBROUTINE AGCHCU (IFLG,KDSH)
C
C This routine is called by AUTOGRAPH as the curves are being drawn.
C If IFLG is zero, a curve is about to be drawn; we set the color
C appropriately and increase the line width to twice normal. If
C IFLG is non-zero, a curve has just been drawn; we return the color
C and line width to their normal values.
C
        IF (IFLG.EQ.0) THEN
          CALL SFLUSH
          CALL GSPLCI (IABS(KDSH)+1)
          CALL GSLWSC (2.)
        ELSE
          CALL SFLUSH
          CALL GSPLCI (1)
          CALL GSLWSC (1.)
        END IF
C
C Done.
C
        RETURN
C
      END



This archive was generated by hypermail 2b29 : Wed Jun 28 2000 - 09:45:36 MDT