Coyote Graphics Routines

Date: Fri Mar 27 12:14:20 2015

single page | use frames     summary     class     fields     routine details     file attributes


top cgText


cgText, xloc, yloc [, text] [, /ADDCMD] [, ALIGNMENT=integer] [, CHARSIZE=float] [, COLOR=string/integer/long] [, /DATA] [, /DEVICE] [, FONT=integer] [, MAP_OBJECT=object] [, /NORMAL] [, ORIENTATION=float] [, OUTLOC=various] [, /PLACE] [, TT_FONT=string] [, WIDTH=float] [, /WINDOW] [, _REF_EXTRA=_REF_EXTRA]

Provides a device-independent and color-model-independent way to write text into a graphics window. It is a wrapper to the XYOUTS command.


xloc in required type=depends

The X location of the text.

yloc in required type=depends

The Y location of the text.

text in optional type=string

The text to output. By default, the calling sequence of the program.


ADDCMD in optional type=boolean default=0

Set this keyword to add the command to an cgWindow. Setting this keyword automatically sets the WINDOW keyword, but the command does not erase the graphics window as it would normally.

ALIGNMENT in optional type=integer default=0

Set this keyword to indicate the alignment of the text with respect to the x and y location. 0 is left aligned, 0.5 is centered, and 1.0 is right aligned. The alignment is set to 0.5 if PLACE is set and ALIGNMENT is unspecified. Otherwise, the default is 0.

CHARSIZE in optional type=float default=cgDefCharSize()

The character size for axes annotations. Uses cgDefCharSize to select default character size, unless !P.Charsize is set, in which case !P.Charsize is always used.

COLOR in optional type=string/integer/long default=opposite

The color of the text. Color names are those used with cgColor.

DATA in optional type=boolean

Set this keyword to indicate xloc and yloc are in data coordinates. Data coordinates are the default, unless DEVICE or NORMAL is set.

DEVICE in optional type=boolean

Set this keyword to indicate xloc and yloc are in device coordinates.

FONT in optional type=integer default=!P.Font

The type of font desired. By default, !P.Font.

MAP_OBJECT in optional type=object

If you are drawing on a map projection set up with Map_Proj_Init and using projected meter space, rather than lat/lon space, then you can use this keyword to provide a cgMap object that will allow you to convert the x and y parameters from longitude and latitude, respectively, to projected meter space before drawing.

NORMAL in optional type=boolean

Set this keyword to indicate xloc and yloc are in normalized coordinates.

ORIENTATION in optional type=float default=0.0

Use this keyword to specify the counterclockwise angle of rotation of the text in degrees from the horizontal.

OUTLOC out optional type=various

Only used if PLACE is set, this is a two-element array containing the xloc and yloc of the cursor position in the window.

PLACE in optional type=boolean

Set this keyword if you wish to click the cursor in the graphics window to place the text. If this keyword is set, you do not need to specify the xloc and yloc positional parameters. The first positional parameter is assumed to be the text. The clicked location will be returned in the OutLoc variable. If the Alignment keyword is not set, it will be set to 0.5 to set "center" as the default placement alignment. This has been modified to allow this keyword to work in a resizeable graphics window as well. Clicking once in the window will set the parameters so you don't have to click every time the window is resized.

TT_FONT in optional type=string

The true-type font to use for the text. Only used if FONT=1.

WIDTH out optional type=float

Set this keyword to a named variable in which to return the width of the text string, in normalized coordinate units. Note that output keyword values cannot be returned from the routine if the command is being executed in a cgWindow.

WINDOW in optional type=boolean

Set this keyword to add the command to the in the current cgWindow application.

_REF_EXTRA in optional

Any IDL XYOutS keyword not defined here is allowed in the program.


Used like the IDL XYOUTS command:

IDL> cgText, 0.5, 0.5, 'This is sample text', ALIGNMENT=0.5, /NORMAL IDL> cgText, /PLACE, 'Use the cursor to locate this text', COLOR='dodger blue'

Author information



David W. Fanning 1645 Sheely Drive Fort Collins, CO 80526 USA Phone: 970-221-0438 E-mail: Coyote's Guide to IDL Programming:


Copyright (c) 2010-2012, Fanning Software Consulting, Inc.


Change History:

Written, 19 November 2010. DWF. Corrected a problem with setting text color and added PLACE and OUTLOC keywords. 25 Nov 2010. DWF. Humm, that text color problem got reset to the old way! Sheesh! Fixed. 9 Dec 2010. DWF. Modified the way the default color is selected. Drawing with DECOMPOSED if possible. 30 Dec 2010. DWF. Keywords collected with _REF_EXTRA so WIDTH can be returned. Added WIDTH keyword. 6 Jan 2011. DWF. Moved setting to decomposed color before color selection process to avoid PostScript background problems when passed 24-bit color integers. 12 Jan 2011. DWF. Added Window keyword. 24 Jan 2011. DWF. Added ability to return WIDTH from resizeable graphics windows and added ADDCMD keyword. 24 Feb 2011. DWF. Modified error handler to restore the entry decomposition state if there is an error. 17 March 2011. DWF Modified to allow the user to place the text in a resizeable graphics window. 13 Dec 2011. DWF. Modified to use cgDefaultColor for default color selection. 24 Dec 2011. DWF. Modifications to the way I obtain the WIDTH when adding the command to a cgWindow. 26 Jan 2012. DWF. Added MAP_OBJECT keyword so that I can draw text on plots using a cgMap map coordinate object. 29 June 2012. DWF. Added the ability to use escape characters in plot titles to specify cgSymbol symbols. 27 July 2012. DWF. Added ORIENTATION keyword to make it explicit, and improved documentation. 3 Aug 2012. DWF.

File attributes

Modification date: Fri Mar 27 11:07:35 2015
Lines: 345
Docformat: rst rst