plotidl-programming-language

How to add a vertical line to a line plot in IDL?


I have a plot that I have created as such using a vector c

hist_c=histogram(c,binsize=0.002,locations=locs_c,min=0.000,max=1.000)
pdf_c=float(hist_c)/n_elements(c)
ppdf_c=plot(locs_c,pdf_c,xtitle='c',ytitle='freq')

I would like to add the vertical line x=0.92 over the line plot I created. The function oplot requires an array, so I am not sure how I can do this.


Solution

  • Typically, you create simple arrays to plot:

    xvalue = 0.92
    line = plot(fltarr(2) + xvalue, ppdf_c.yrange, /overplot)
    

    where xvalue is the x-coordinate of your vertical line and ppdf_c is the reference to your last plot.

    For reference for those using direct graphics, this would be how to do it in direct graphics:

    xvalue = 0.92
    oplot, fltarr(2) + xvalue, !y.crange