; File: immigration.pro ; Read in a table of immigration data and make a stacked bar chart of ; data for four specific countries ; Get input data and extract the items of interest ; Allocate space for immigration data nrow = 8 ncol = 26 allin = lonarr(ncol, nrow) ; Read in immigration data openr, 1, 'immigration_mod.dat' readf, 1, allin close, 1 ; Extract data for Austria, France, Germany, Italy data = allin[[3,8,9,12], *] ; Make an array of country names names = ['Austria', 'France', 'Germany', 'Italy'] ; Produce intermediate data which will be needed for a stacked bar chart ; Produce a new array of values giving total height for each entry accum = data; for i=1, nrow-1 do begin accum(*, i) = accum(*, i) + accum(*, i-1) endfor ; Choose a set of random color indices to color the individual data items colors = fix(256*randomu(1995687, ncol)) ; Set up some specific stuff for the graphics system ; Handle TrueColor displays DEVICE, DECOMPOSED=0 ; Load color table LOADCT, 5 ; Save existing draw color, and then make axes black PRE_PCOLOR = !P.COLOR !P.COLOR=0 ; Make the window persistent window, 0, retain = 2 ; Now make the plot ; Draw a bar plot of the last entry (tallest bars) bar_plot, accum[*,nrow-1], colors=replicate(colors[nrow-1], nrow), $ background=255, barnames=names, title='Immigration by Decade' ; Overdraw bar plots of the remaining entries in ; inverse order (tallest to shortest bars) for i=nrow-2, 0, -1 do begin bar_plot, accum[*,i], colors=replicate(colors[i], nrow), /overplot endfor ; Restore draw color !P.COLOR = PRE_PCOLOR end