; docformat = 'rst' ;+ ; This is an example program to demontrate how to create a fitted Gaussian plot ; with Coyote Graphics routines. ; ; :Categories: ; Graphics ; ; :Examples: ; Save the program as "fitted_gaussian_plot.pro" and run it like this:: ; IDL> .RUN fitted_gaussian_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 Fitted_Gaussian_Plot ; Set up variables for the plot. Normally, these values would be ; passed into the program as positional and keyword parameters. data = cgDemoData(5) ; Draw the histogram plot, setting the MISSING keyword to 0, to ; eliminate the many missing data values in this data set. We return ; the histogram data, the starting locations of each bin, and the binsize ; the program used to calculate the histogram. cgHistoplot, data, /FILL, HISTDATA=h, LOCATIONS=loc, BINSIZE=binsize, MISSING=0 ; We want to fit the bin centers, so we need to find them first. binCenters = loc + (binsize / 2.0) yfit = GaussFit(binCenters, h, coeff, NTERMS=3) thick = (!D.Name EQ 'PS') ? 5 : 3 cgPlot, binCenters, yfit, COLOR='dodger blue', THICK=thick, /OVERPLOT ; Add plot annotation. maxfit = String(coeff[0], FORMAT='(F0.2)') centerfit = String(coeff[1], FORMAT='(F0.2)') fwhm = String(2 * SQRT(2 * ALOG(2)) * coeff[2], FORMAT='(F0.2)') cgText, 0.6, 0.75, /NORMAL, 'Maximum: ' + maxfit, COLOR='navy' cgText, 0.6, 0.70, /NORMAL, 'Center: ' + centerfit, COLOR='navy' cgText, 0.6, 0.65, /NORMAL, 'FWHM: ' + fwhm, COLOR='navy' END ;***************************************************************** ; This main program shows how to call the program and produce ; various types of output. ; Display the plot in a graphics window. Fitted_Gaussian_Plot ; Display the plot in a resizeable graphics window. cgWindow, 'Fitted_Gaussian_Plot', Background='White', \$ WTitle='Fitted Gaussian Plot in a Resizeable Graphics Window' ; Create a PostScript file. cgPS_Open, 'fitted_gaussian_plot.ps' Fitted_Gaussian_Plot cgPS_Close ; Create a PNG file with a width of 600 pixels. cgPS2Raster, 'fitted_gaussian_plot.ps', /PNG, Width=600 END