Discussion:
Plotting a horizontal line over a cgImage
(too old to reply)
Christina Haig
2016-08-29 16:03:09 UTC
Permalink
This question probably has a very specific audience, but anyone who might be able to help me I would greatly appreciate.

Here is a good example of a cgimage plot, somewhat complex, but nothing untoward:

p = pos[*,0]
cgimage,data1,/DEVICE,/SCALE,/AXES,position=[p[0],p[1],p[2],p[3]],$
xrange=[mint,maxt],yrange=[minp,maxp],charsize=3,$
AXKEYWORDS={xtickformat:'(A1)',ylog:1,yticks:2,$
ytickname:['10!e0','10!e1','10!e2']},/noerase

As you can see, the yrange goes roughly from 1 to 100ish. I would like to plot a horizontal line at 2 that references the axes set in the cgimage command, and at the position of the same (there are 12 total plots in my output). Now oplot obviously does not allow the position command. So I attempted to cleverly use the cgplot command to overplot the line.

cgplot,[mint,maxt],[2.0,2.0],thick=4,line=5,color=255,$
position=[p[0],p[1],p[2],p[3]],/overplot

However nothing shows up in my plot. Can anyone advise me how I might solve this problem?

Thanks,
Christina
wlandsman
2016-08-29 18:20:01 UTC
Permalink
Post by Christina Haig
As you can see, the yrange goes roughly from 1 to 100ish.
Actually we can't see ;-) We (the readers of this newsgroup) don't know the content of your variables, and we can't see the output plot.

But your code looks like it should work. Does the CGPLOT command come immediately after the CGIMAGE command or is there something in between that could reset the positioning?

Also I would set COLOR='green' (or something similar) in your CGPLOT command, in case there is something funky with the color table.

Also check the coordinate transformation between data and device coordinates

IDL> print,convert_coord(mint,maxt],[2.0,2.0],/data,/to_device)

to make sure the line is in the physical area of the window. --Wayne
Christina Haig
2016-08-29 19:29:51 UTC
Permalink
Post by wlandsman
Post by Christina Haig
As you can see, the yrange goes roughly from 1 to 100ish.
Actually we can't see ;-) We (the readers of this newsgroup) don't know the content of your variables, and we can't see the output plot.
But your code looks like it should work. Does the CGPLOT command come immediately after the CGIMAGE command or is there something in between that could reset the positioning?
Also I would set COLOR='green' (or something similar) in your CGPLOT command, in case there is something funky with the color table.
Also check the coordinate transformation between data and device coordinates
IDL> print,convert_coord(mint,maxt],[2.0,2.0],/data,/to_device)
to make sure the line is in the physical area of the window. --Wayne
Hi Wayne, thanks for your reply. I decided to try your suggestion of 'green', and also 'black', just in case. Also, my color table goes from black to white (255 to 0), and I tried both of those.

I also tried the convert_coord command, but /to_device gives some weirdly large numbers that I don't quite understand. I then tried convert_coord with /to_normal and got:

0.088541664 0.95833331 0.0000000
0.35069446 0.95833331 0.0000000

This looks like it should be somewhere in the plot area, in the general region of the upper-lefthand-corner where the underlying plot is. There is nothing between the cgplot and cgimage command. Is there something about either cgplot or cgimage that doesn't like one writing over the other perhaps? Is there a way to override this?
wlandsman
2016-08-30 13:59:29 UTC
Permalink
I had tested your code by putting in fake data below and I see the horizontal line at y=2. --Wayne


cgimage,dist(512),/DEVICE,/SCALE,/AXES,position=[0.2,0.2,0.9,0.9],$
xrange=[1,10],yrange=[1,100],charsize=3,$
AXKEYWORDS={xtickformat:'(A1)',ylog:1,yticks:2,$
ytickname:['10!e0','10!e1','10!e2']},/noerase


cgplot,[1,10],[2.0,2.0],thick=4,line=5,color='green',$
position=[0.2,0.2,0.9,0.9],/overplot
Christina Haig
2016-08-29 18:20:05 UTC
Permalink
One edit to say I changed to:

cgplot,[mint,maxt],[2.0,2.0],thick=4,line=5,color=255,$
position=[p[0],p[1],p[2],p[3]],/ylog,/overplot

However, still nothing.
Jeremy Bailin
2016-09-22 21:08:26 UTC
Permalink
Post by Christina Haig
This question probably has a very specific audience, but anyone who might be able to help me I would greatly appreciate.
p = pos[*,0]
cgimage,data1,/DEVICE,/SCALE,/AXES,position=[p[0],p[1],p[2],p[3]],$
xrange=[mint,maxt],yrange=[minp,maxp],charsize=3,$
AXKEYWORDS={xtickformat:'(A1)',ylog:1,yticks:2,$
ytickname:['10!e0','10!e1','10!e2']},/noerase
As you can see, the yrange goes roughly from 1 to 100ish. I would like to plot a horizontal line at 2 that references the axes set in the cgimage command, and at the position of the same (there are 12 total plots in my output). Now oplot obviously does not allow the position command. So I attempted to cleverly use the cgplot command to overplot the line.
cgplot,[mint,maxt],[2.0,2.0],thick=4,line=5,color=255,$
position=[p[0],p[1],p[2],p[3]],/overplot
However nothing shows up in my plot. Can anyone advise me how I might solve this problem?
Thanks,
Christina
Are minp and maxp what you think they are?

-Jeremy.
Christina Haig
2016-09-23 19:04:38 UTC
Permalink
Post by Jeremy Bailin
Post by Christina Haig
This question probably has a very specific audience, but anyone who might be able to help me I would greatly appreciate.
p = pos[*,0]
cgimage,data1,/DEVICE,/SCALE,/AXES,position=[p[0],p[1],p[2],p[3]],$
xrange=[mint,maxt],yrange=[minp,maxp],charsize=3,$
AXKEYWORDS={xtickformat:'(A1)',ylog:1,yticks:2,$
ytickname:['10!e0','10!e1','10!e2']},/noerase
As you can see, the yrange goes roughly from 1 to 100ish. I would like to plot a horizontal line at 2 that references the axes set in the cgimage command, and at the position of the same (there are 12 total plots in my output). Now oplot obviously does not allow the position command. So I attempted to cleverly use the cgplot command to overplot the line.
cgplot,[mint,maxt],[2.0,2.0],thick=4,line=5,color=255,$
position=[p[0],p[1],p[2],p[3]],/overplot
However nothing shows up in my plot. Can anyone advise me how I might solve this problem?
Thanks,
Christina
Are minp and maxp what you think they are?
-Jeremy.
Apologies for the delay in replying. This was in fact the problem. The problem was my data was already logarithmic, and thus my axes were 0 - 2.0. My fault for not remembering that /ylog just changes the tick names of the axes on cgplot, but the min and max has to be already logged.

So what I needed was to put in log(2.0), instead of just 2.0. I'll leave this thread up in case other people have trouble with logarithmic cgplot.
Loading...