; docformat = 'rst' ;+ ; This is an example program to demonstrate how to create a line plot with a legend using ; IDL function graphics routines. ; ; :Categories: ; Graphics ; ; :Examples: ; Save the program as "plot_with_legend_fg.pro" and run it like this:: ; IDL> plot_with_legend_fg ; ; :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 February 2014 by Matthew Argall and David W. Fanning. ; ; :Copyright: ; Copyright (c) 2014, Fanning Software Consulting, Inc. ;- PRO Plot_with_Legend_FG ; Don't forget compile options in IDL 8 programs or there can be problems Compile_Opt idl2 ; Set up variables for the plot. Normally, these values would be ; passed into the program as positional and keyword parameters. ; Create two random vectors. data_1 = cgDemoData(17) data_2 = cgDemoData(17) ; Calculate the data range, so you can create a plot with room at the top ; of the plot for the legend. maxData = Max(data_1) > Max(data_2) minData = Min(data_1) > Min(data_2) dataRange = maxData - minData yrange = [MinData, maxData + (dataRange*0.25)] ; Legend Properties items = ['Experiment 1', 'Experiment 2'] psyms = [-15, -16] colors = ['red7', 'blu7'] ;Plot the data fgWin = Window() fgPlot = Plot(data_1, Symbol='Circle', /Sym_Filled, Color='Red', YRange=yrange, YStyle=1, $ XTitle='Time', YTitle='Signal', Name='Experiment 1', /Current) fgOPlot = Plot(data_2, Symbol='Square', /Sym_Filled, Color='Blue', Overplot=fgPlot, $ Name='Experiment 2') fgLegend = Legend(/Auto_Text_Color, Position=[5, 120], Target=[fgPlot, fgOPlot], /Data, $ Horizontal_Alignment='Left') ; Save the plot as a PostScript file. fgWin.save, 'plot_with_legend_fg.eps' ; Save the plot as a PNG raster file with width 600 pixels. Until IDL 8.3, this is low resolution. ;fgWin.save, 'plot_with_legend_fg.png', Width=600 ; Better to save the PNG file in full resolution and resize with ImageMagick. fgWin.save, 'plot_with_legend_fg_fullsize.png' Spawn, 'convert plot_with_legend_fg_fullsize.png -resize 600 plot_with_legend_fg.png' END