; docformat = 'rst' ;+ ; This is an example program to demonstrate how to create a filled area plot, ; with the fill color a function of Y, with Coyote Graphics routines. ; ; :Categories: ; Graphics ; ; :Examples: ; Save the program as "height_filled_area_plot.pro" and run it like this:: ; IDL> .RUN height_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, 27 August 2013 by David W. Fanning. ; ; :Copyright: ; Copyright (c) 2013, Fanning Software Consulting, Inc. ;- PRO Height_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 = 10 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 ; Scale the y data for colors. cgLoadCT, 4, /Brewer, Clip=[50, 230] ; Draw the area under the curve with scaled colors. min_y = Min(y[lowIndex:highIndex], Max=max_y) colors = BytScl(y, MIN=min_y, MAX=max_y) FOR j=lowIndex,highIndex-1 DO BEGIN xpoly = [x[j], x[j], x[j+1], x[j+1], x[j]] ypoly = [!Y.CRange[0], y[j], y[j+1], !Y.CRange[0], !Y.CRange[0]] cgColorFill, xpoly, ypoly, Color=colors[j] ENDFOR ; 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]] thick = (!D.Name EQ 'PS') ? 5 : 2 cgPolygon, xpoly, ypoly, color='charcoal', Thick=2 ; 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' cgOPlot, x, y, Color='navy', 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. Height_Filled_Area_Plot ; Display the plot in a resizeable graphics window. cgWindow, 'Height_Filled_Area_Plot', WTitle='Filled Area Plot Colored by Height' ; Create a PostScript file. cgPS_Open, 'height_filled_area_plot.ps' Filled_Area_Plot cgPS_Close ; Create a PNG file with a width of 600 pixels. cgPS2Raster, 'height_filled_area_plot.ps', /PNG, Width=600 END