PRO ColorFill ; The data to plot. x = Findgen(101) y = 4 * Sin(x * !DtoR) / Exp( (x-15) / 25.) ; Initial data plot. cgDisplay, 750, 500, Title='Filled Area Under a Curve' cgPlot, x, y, Background=background, Color='red', /NODATA ; Set up the polygon to fill with color. low = 20 high = 45 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] IF x(lowIndex) LT low THEN lowIndex = lowIndex + 1 IF x(highIndex) GT high THEN highIndex = highIndex - 1 ; Fill the polygon with color. xpoly = [ low, low, x[lowIndex:highIndex], high, high] ypoly = [!Y.CRange[0], lowY, y[lowIndex:highIndex], highY, !Y.CRange[0]] cgColorFill, xpoly, ypoly, Color='dodger blue' ; Repair plot damage caused by the polygon fill and spruce up the plot. cgPlotS, xpoly, ypoly, Color='navy', Thick=2 cgPlot, x, y, /NoData, /NoErase cgOPlot, x, y, Color='red', Thick=3 END