; docformat = 'rst' ;+ ; This is an example program to demonstrate how to create a filled area plot ; with Coyote Graphics routines. ; ; :Categories: ; Graphics ; ; :Examples: ; Save the program as "filled_area_plot.pro" and run it like this:: ; IDL> .RUN filled_area_plot ; ; :Author: ; FANNING SOFTWARE CONSULTING:: ; David W. Fanning ; 1645 Sheely Drive ; Fort Collins, CO 80526 USA ; Phone: 970-221-0438 ; E-mail: david@idlcoyote.com ; Coyote's Guide to IDL Programming: http://www.idlcoyote.com ; ; :History: ; Change History:: ; Written, 23 January 2013 by David W. Fanning. ; ; :Copyright: ; Copyright (c) 2013, Fanning Software Consulting, Inc. ;- PRO Filled_Area_Plot ; Set up variables for the plot. Normally, these values would be ; passed into the program as positional and keyword parameters. x = Findgen(101) y = 4 * Sin(x * !DtoR) / Exp( (x-15) / 25.) ; Draw the plot axes. cgDisplay, /Free, Title='Fill Area Under a Curve' cgPlot, x, y, /NoData ; Set up the low and high x indices of the area under the curve ; you want to fill. low = 20 high = 45 ; Find the y indices associated with the low and high indices. lowY = 4 * Sin(low * !DtoR) / Exp( (low-15) / 25.) highY = 4 * Sin(high * !DtoR) / Exp( (high-15) / 25.) indices = Value_Locate(x, [low, high]) lowIndex = indices[0] highIndex = indices[1] ; Make sure the indices you find correspond the the right X indices. IF x(lowIndex) LT low THEN lowIndex = lowIndex + 1 IF x(highIndex) GT high THEN highIndex = highIndex - 1 ; Create closed polygons to color fill. xpoly = [ low, low, x[lowIndex:highIndex], high, high] ypoly = [!Y.CRange[0], lowY, y[lowIndex:highIndex], highY, !Y.CRange[0]] ; Fill the polygon with color. cgColorFill, xpoly, ypoly, Color='dodger blue' thick = (!D.Name EQ 'PS') ? 4 : 2 cgPlotS, xpoly, ypoly, Color='navy', Thick=thick ; Redraw the plot to repair damage caused by color filling and to draw the data. cgPlot, x, y, /NoData, /NoErase, XTitle='X Axis', YTitle='Y Axis' thick = (!D.Name EQ 'PS') ? 6 : 3 cgOPlot, x, y, Color='red', Thick=thick END ;***************************************************************** ; This main program shows how to call the program and produce ; various types of output. ; Display the plot in a graphics window. Filled_Area_Plot ; Display the plot in a resizeable graphics window. cgWindow, 'Filled_Area_Plot', WTitle='Filled Area Plot in a Resizeable Graphics Window' ; Create a PostScript file. cgPS_Open, 'filled_area_plot.ps' Filled_Area_Plot cgPS_Close ; Create a PNG file with a width of 600 pixels. cgPS2Raster, 'filled_area_plot.ps', /PNG, Width=600 END