Plotting Data on Maps
You can annotate plots easily using the Direct graphics programming capabilities of IDL. Creating map displays using Direct graphics routines is not as convenient as using iMap, but may be desirable if you are incorporating maps into a larger, widget-based application.
To plot the location of the five cities as shown in the following figure, create three arrays for the data to plot: one each to hold latitude and longitude locations, and one to hold the names of the cities.
- From the IDL command line, type the following command to create a five-element array of floating-point values representing latitudes in degrees North of zero.
- The values in LONS are negative because they represent degrees West of zero longitude.
- Create a five-element array of string values. Text strings can be enclosed in either single or double quotes.
- Since we are using Direct graphics, tell IDL to use a maximum of 256 colors. Load a gray scale color table and set the background to white and the foreground to black:
- Draw a Mercator projection and define an area that encompasses the United States and Central America.

Place a plotting symbol at the location of each city. The PSYM keyword creates diamond-shaped plotting symbols. SYMSIZE controls the size of the plotting symbols.- Place the names of the cities near their respective symbols. XYOUTS draws the characters for each element of the array CITIES at the corresponding location specified by the array elements of LONS and LATS. The CHARTHICK keyword controls the thickness of the text characters and the CHARSIZE keyword controls their size (1.0 is the default size). Setting the ALIGN keyword to 0.5 centers the city names over their corresponding data points.
lats=[40.02,34.00,38.55,48.25,17.29]
lons=[-105.16,-119.40,-77.00,-114.21,-88.10]
cities=['Boulder, CO','Santa Cruz, CA',$
'Washington, DC','Whitefish, MT','Belize, Belize']
DEVICE, RETAIN=2, DECOMPOSED=0
LOADCT, 0
!P.BACKGROUND=255
!P.COLOR=0
MAP_SET, /MERCATOR, /GRID, /CONTINENT, LIMIT=[10,-130,60,-70]
PLOTS, lons, lats, $
PSYM=4, SYMSIZE=1.4, $
COLOR=120
The result shows a window with the map projection of the area with the plotting symbols (shown here).
XYOUTS, lons, lats, cities, COLOR=80, $
CHARTHICK=2, CHARSIZE=1.25, ALIGN=0.5
Now the plotting symbols and city names display on the map:

Reading Latitudes and Longitudes
If a map projection is displayed, IDL can return the position of the cursor over the map in latitude and longitude coordinates.
- Enter the command:
- When you are finished with your map, close the graphics window.
CURSOR, lon, lat & PRINT, lat, lon
The CURSOR command reads the "X" and "Y" positions of the cursor when the mouse button is pressed and returns those values in the LON and LAT variables. Use the mouse to move the cursor over the map window and click on any point. The latitude and longitude of that point on the map are printed in the Output Log.