; docformat = 'rst' ; ; NAME: ; plotBiblioYear ; PURPOSE: ; Plot a histogram of publications against years. ; ;+ ; :Description: ; Plot a histogram of publications against years. ; ; :Categories: ; Bibliography ; ; :Params: ; bib: in, required, type=structure ; A structure of bibliography information. ; dump: in, optional, type=string, default='./bibHistoYear.png' ; Path to the figure file. ; ; :Keywords: ; cumulative: in, optional, type=boolean, default=0 ; Overplot the cumulative histogram. ; config: in, optional, type=structure/string ; Configuration structure (see bibliLoadConfig) or path to it. ; ; :Examples: ; Get the list of record from the author, and plot it: ; IDL> ref = getAuthorRecord('carry, b', /refereed) ; IDL> plotBiblioYear, ref, 'Carry.png' ; ; :Uses: ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Written in October 2015, B. Carry (OCA) ; 2016 Dec. - B. Carry (OCA) - Improved cumulative plot ; 2017 May - B. Carry (OCA) - Adapted Y axis to very high citation counts ;- pro plotBiblioYear, bib, dump, cumulative=cumulative, config=config COMPILE_OPT hidden, idl2 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--I.1-- Verify Input Syntax ---------------------------------------------------------- if not keyword_set(bib) then begin message, /IOERROR, 'Syntax error: plotBiblioYear, bib [, dump]' return endif ;--I.2-- Set Default Figure Name ------------------------------------------------------ if not keyword_set(dump) then dump='./bibHistoYear.eps' ;--I.3-- Test File for Writing -------------------------------------------------------- ; if not file_test(dump,/write) then begin ; message, /IOERROR, 'Output file cannot be generated: '+strtrim(dump,2) ; return ; endif ;--I.4-- Default Configuration -------------------------------------------------------- ;--I.4.1-- Sources Directory biblioPATH = ROUTINE_FILEPATH( 'plotbiblioyear' ) biblioPATH = strmid( biblioPATH, 0, strlen(biblioPATH)-18) ;--I.4.2-- Read Configuration File confDefault = biblioLoadConfig(biblioPATH+'config.ini') ;--I.4.3-- Use Default Configuration, OR, if not keyword_set(conf) then conf=confDefault else begin dimC=size(conf) ;--I.4.3/A-- Use Provided Configuration if dimC[dimC[0]+1] eq 8 then begin conf = updateStructure( confDefault, conf ) ;--I.4.3/B-- Read & Use Provided Configuration endif else begin conf = biblioLoadConfig( conf ) conf = updateStructure( confDefault, conf ) endelse endelse confTag = tag_names(conf) ;--I.5-- Cumulative Mode -------------------------------------------------------------- ; doCumul=0 ; if keyword_set(cumulative) then begin ; dimC=size(cumulative) ; if dimC[dimC[0]+1] ne 8 then doCumul=1 ; endif ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Prepare the Bibliography for Plotting -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- Timeline --------------------------------------------------------------------- yearF = min(bib.year) yearL = max(bib.year) yearBorder = max([ yearL+ (yearL-yearF)*0.8, yearL+5, yearF-1+8 ] ) yearRange = [yearF-1, yearBorder] uType = bib[uniq( bib.type, sort(bib.type) )].type nbType = n_elements(uType) ;--II.2-- Counting Entries ------------------------------------------------------------- maxHisto = 0 for kType=0, nbType-1 do begin cur = where( strcmp(bib.type, uType[kType]) ) histo =histogram( [bib[cur].year], binsize=1 ) maxHisto = max( [maxHisto, max(histo)]) endfor histoAll = histogram( [bib.year], binSize=1, loc=xArr ) ; print, maxhisto numRange = [0, max([5,maxHisto*1.1])] ; numRange = [0, maxHisto*1.1] ; potential options; ; -stacked / side by side ; -caption location ; ; ; ;--II.3-- Plotting Options ------------------------------------------------------------- xKey = yearL + 1.5 xLen = 1 yKey = numRange[1]*0.10 yLen = numRange[1]*0.08 yShi = numRange[1]*0.12 xTickInt= 2 xMinor = 2 yTickInt= 5 yMinor = 5 if numRange[1] le 10 then begin yTickInt= 1 yMinor = 1 endif if numRange[1] gt 20 then begin yTickInt= 10 yMinor = 5 endif if numRange[1] gt 100 then begin yTickInt= 20 yMinor = 4 endif if numRange[1] gt 200 then begin yTickInt= 50 yMinor = 5 endif if numRange[1] gt 400 then begin yTickInt= 100 yMinor = 5 endif plotPosition = [0.10,0.12,0.90,0.95] ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- III -- Prepare the Plot Area & Ranges -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--III.1-- Save Current Device Status -------------------------------------------------- SetDecomposedState, 1, CurrentState=theState thisDevice = !D.Name ;--III.2-- Set Device to PS & Define Graphic Window ------------------------------------ ; set_plot, 'PS' cgPS_open, Filename=dump, /metric, /decomposed, /encapsulated, $ xsize=30, ysize=15, language_level=2, /quiet ;--III.3-- Set Graphics Area ----------------------------------------------------------- cgPlot, xArr, histoAll, /NoData, /NORMAL, $ position=plotPosition, $ xStyle=1, $ xRange=yearRange, xTickInterval=xTickInt, xMinor=xMinor, $ yStyle=1+8*keyword_set(cumulative), $ yRange=numRange, yTickInterval=yTickInt, yMinor=yMinor, $ yTitle='Number of reference per year' ; ; cgHistoPlot, bib.year, /NoData, /NORMAL, binsize=1, $ ; position=[0.08,0.12,0.95,0.95], $ ; xStyle=1, xRange=yearRange, xminor=2, $ ; yTitle='Number of references' ; /oProbability ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- IV -- Plot Each Type of Bibliographic Entry -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; for kType=0, nbType-1 do begin ; print, kType, nbType, uType[kType] strType = uType[kType] strput, strType, strUpCase(strmid(strType,0,1)),0 cur = where( strcmp(bib.type, uType[kType]), nbCur ) set = where( strcmp(confTag,uType[kType],/fold) ) set=set[0] cgHistoPlot, [bib[cur].year], /oPlot, binsize=1, $ color=conf.(set).color, thick=conf.(set).thick, $ xStyle=1, xRange=yearRange, $ minInput=yearF, maxInput=yearL, $ dataColorName='black' cgHistoPlot, [bib[cur].year], /oPlot, binsize=1, $ color=conf.(set).color, thick=conf.(set).thick, /fill, $ xStyle=1, xRange=yearRange, $ minInput=yearF, maxInput=yearL, $ dataColorName='black' ;-- key cgColorFill, xKey+xLen*[0,1,1,0,0], yKey+kType*yShi+yLen*[0,0,1,1,0], color=conf.(set).color cgPlot, /over, xKey+xLen*[0,1,1,0,0], yKey+kType*yShi+yLen*[0,0,1,1,0], thick=conf.(set).thick cgText, xKey+xLen*1.2, yKey+kType*yShi+yLen*0.3, strType+' ('+strtrim(string(nbCur),2)+')' ;square + type endfor ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- V -- Plot Cumulative Entry -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; if keyword_set(cumulative) then begin dimC=size(cumulative) if dimC[dimC[0]+1] eq 8 then begin ;--I.5.1-- Compute Cumulative Count of Citations histo = histogram( [cumulative.year], binSize=1, loc=xCumul ) cumul = total(histo, /cumulative) maxCumul=max(cumul) ;--I.5.2-- Retrieve Citation Label & Uppercase it set = where( strcmp(confTag,cumulative[0].type,/fold) ) set=set[0] strType = strLowCase(cumulative[0].type) strput, strType, strUpCase(strmid(strType,0,1)),0 ;--I.5.2 cgPlot, /OverPlot, xKey+xLen*[0,1], yKey+kType*yShi+yLen*[0.5,0.5], $ lineStyle=conf.(set).line, color=conf.(set).color, thick=conf.(set).thick cgPlot, /OverPlot, xKey+xLen*0.5, yKey+kType*yShi+yLen*0.5, $ pSym=conf.(set).symbol, color=conf.(set).color, thick=conf.(set).thick cgText, xKey+xLen*1.2, yKey+kType*yShi+yLen*0.3, $ strType+' ('+strtrim(string(maxCumul,format='(I)'),2)+')' cgPlot, xCumul+0.5, cumul, /NoErase, /Normal, $ position=plotPosition, $ xStyle=1+4, xRange=yearRange, $ yStyle=1+4, yRange=[0, maxCumul*1.1], $ psym=conf.(set).symbol, $ color=conf.(set).color, thick=conf.(set).thick cgPlot, xCumul+0.5, cumul, /Overplot, $ lineStyle=conf.(set).line, $ color=conf.(set).color, thick=conf.(set).thick cgAxis, yAxis=1, yRange=[0, maxCumul*1.1], yStyle=1, $ yTitle='Cumulative number of '+strType, $ yMinor=5 endif endif ;--VI.1-- Close PS File ----------------------------------------------------------------- cgPS_close, /png;, Delete_PS=1 ;--VI.3-- Revert Device & Decomposed Mode Status --------------------------------------- set_plot, thisDevice SetDecomposedState, theState end