Hello All:
Summary: My (only slightly) more complex plot()s usually break legend. Why is this, is there a workaround? Is there some "resetting" I have to do to avoid this?
Specific example:
The following code causes failure of the legend , repeatably for me. I only get the first symbol in the legend, the rest are not present. This is a problem I have in general with legend, though sometimes it works with e.g. 3 very simple plots or scatterplots. ***I would be super-grateful if someone could tell me why and suggest fix.***
Numerous other legend fail examples on request.
(It might be helpful to some people to note the zero sample width hack for points, not lines. This was surprisingly hard to track down on the net.)
================================================
pro plot251013c2
; simple fake data example
tt=10^(2+findgen(50)/50*3.)
imag=14.+findgen(50)/50.*6.
sig=0.05*abs(imag)
; NOW NEW METHOD WITH FUNCTIONS NOT PLOT PROS...------------------
yerror=replicate(0.05,n_elements(imag))
p1 = SCATTERPLOT(tt, imag,/xlog,name='NUT',$
XRANGE=[10^1.75,10^5.25], yrange=[22.,13.],xsty=1,ysty=1 )
p1.symbol='o'
p1.font_size=2.7
p1.sym_filled=1
p1.sym_size=.6
p1.font_size=12
p1.title="251013C LC"
p1.xtitle='Log t-t0 (s)'
p1.ytitle="mags in given color"
; unam GCN 42242
r_UNAM= [18.50]
p2=scatterplot([8.65*3600.],r_UNAM,/overplot,name='UNAM')
p2.symbol='Plus'
p2.sym_color='red'
p2.sym_size=2.5
p2.sym_thick=2
; 42276 OHP GCN 42276
r_OHP=[21.29]
p3=scatterplot([28.71*3600.],r_OHP,/overplot,name='OHP')
p3.symbol='Square'
p3.sym_color='blue'
p3.sym_size=1.5
p3.sym_filled=1
lgnd = LEGEND(TARGET=[p1, p2,p3], SAMPLE_WIDTH=0,$
HORIZONTAL_SPACING=.1,/AUTO_TEXT_COLOR)
stop
end
================================================
What's going on here is that I am trying to finally enter the 21st century and use the plot function (I'm an old school plot,x,y *procedure* guy), and learn what the heck this "object" programming thing is all about. I think that the function (plot(),errorplot(),scatterplot()) plots look a bit better than the procedures (plot,x,y; errorplot,x,y,sigma), and the legend thing would be spiffy if it worked.
In the greater scheme of things, I plot lots of points and sometimes the lines fitting a function over them. I would never, ever plot points with lines between them, as plot() prefers, extremely rare in my field (but you can line_style='' your way out of this). Other than that, I cannot figure out why there would be a scatterplot and a plot function. So, in the end, the plots look a little better and the possibility to nudge the locations of labels and change the symbols and fonts interactively could be a *tremendous* timesaver if I can figure these out.
-WOuld be ever so appreciative of a fix.
-Advice on general approaches to IDL plotting in the 21st century will be read with great interest and gratitude.
Thanks for helping!