Overplot cgplots in graphics window [message #86333] |
Mon, 28 October 2013 08:00  |
morganlsilverman
Messages: 46 Registered: February 2013
|
Member |
|
|
Hello,
I have several data sets of trajectories that I want to plot together in one graphics window. I am able to rerun the code and have it overplot in the display window but I'm not able to save that. I've tried creating a resizable graphics window but because the cgplots commands are in a loop, IDL continually displays new graphics windows and then crashes. Is there a way that I can rerun my code with a new data set each time and overplot on the same map and then save the graphic without having to just copy and paste my code 3x in the same program? I've included the basis of my plotting. All datasets have the same variable names and I'd like to not make my code gigantic by specifying each separately. Thanks.
Sincerely,
Morgan
; Set up map projection
mapCoord = Obj_New('cgmap', 'Stereographic', Ellipsoid='WGS 84', Limit=limit, $
center_lat=centarlat, center_lon=centerlon, position=pp)
mapCoord -> Draw
cgMap_Grid, map=mapCoord, /box
cgMap_Continents, map=mapCoord, /continents, /countries, /usa
for j=0,n_elements(index)-1 do begin
if (j eq 0 and loc(0) eq 72) then begin
start = 0
stops = loc(j)
endif else begin
if (j eq 0 and loc(0) ne 72) then begin
start = flightloc(index(j)-1)+1
stops = loc(j)
endif else begin
start = loc(j-1)+1
stops = loc(j)
endelse
endelse
cgplots, Avg2000Lon, Avg2000Lat, map=mapCoord, color='blue',/window
cgplots, Avg2500Lon, Avg2500Lat, map=mapCoord, color='green',/window
cgplots, Avg3000Lon, Avg3000Lat, map=mapCoord, color='cyan',/window
cgplots, Avg3500Lon, Avg3500Lat, map=mapCoord, color='magenta',/window
al_legend,['1500 m', '2000 m', '2500 m', '3000 m', '3500 m'], linestyle=[0,0,0,0,0], $
color=['red', 'blue', 'green', 'cyan', 'magenta'], /left, charsize=0.9
cgtext, 0.5*total(!x.window), !y.window[1]+2.5*!d.y_ch_size/!d.y_vsize,'Flight 5 07/11/11 ', /normal,align=0.5
endfor
|
|
|
Re: Overplot cgplots in graphics window [message #86334 is a reply to message #86333] |
Mon, 28 October 2013 08:25   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Morgan Silverman writes:
> I have several data sets of trajectories that I want to plot together in one graphics window. I am able to rerun the code and have it overplot in the display window but I'm not able to save that. I've tried creating a resizable graphics window but because the cgplots commands are in a loop, IDL continually displays new graphics windows and then crashes. Is there a way that I can rerun my code with a new data set each time and overplot on the same map and then save the
graphic without having to just copy and paste my code 3x in the same program?
Well, of course. :-)
Not sure how you found yourself in this mess (I don't see in the code
you provide where you are creating the cgWindow), but the general method
for loading a cgWindow with lots of commands and then making a plot of
it looks like this, in general:
;--------------------------------------------------------
cgWindow
cgControl, Execute=0
cgPlot, cgDemoData(1), YRange=[0,100], /AddCmd
cgLoadCT, 33, NColors=4, Bottom=1
FOR j=0,3 DO BEGIN
cgPlotS, cgDemoData(17), Color=Byte(j) + 1B, /AddCmd
ENDFOR
cgControl, Execute=1
cgControl, Output='overplots.png'
END
;--------------------------------------------------------
Create the cgWindow, turn updating off while you add a bunch of
commands. Then turn window updating on and create the output.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: Overplot cgplots in graphics window [message #86338 is a reply to message #86334] |
Mon, 28 October 2013 10:08   |
morganlsilverman
Messages: 46 Registered: February 2013
|
Member |
|
|
On Monday, October 28, 2013 11:25:45 AM UTC-4, David Fanning wrote:
> Morgan Silverman writes:
>
>
>
>> I have several data sets of trajectories that I want to plot together in one graphics window. I am able to rerun the code and have it overplot in the display window but I'm not able to save that. I've tried creating a resizable graphics window but because the cgplots commands are in a loop, IDL continually displays new graphics windows and then crashes. Is there a way that I can rerun my code with a new data set each time and overplot on the same map and then save the
>
> graphic without having to just copy and paste my code 3x in the same program?
>
>
>
> Well, of course. :-)
>
>
>
> Not sure how you found yourself in this mess (I don't see in the code
>
> you provide where you are creating the cgWindow), but the general method
>
> for loading a cgWindow with lots of commands and then making a plot of
>
> it looks like this, in general:
>
>
>
> ;--------------------------------------------------------
>
> cgWindow
>
> cgControl, Execute=0
>
> cgPlot, cgDemoData(1), YRange=[0,100], /AddCmd
>
> cgLoadCT, 33, NColors=4, Bottom=1
>
> FOR j=0,3 DO BEGIN
>
> cgPlotS, cgDemoData(17), Color=Byte(j) + 1B, /AddCmd
>
> ENDFOR
>
> cgControl, Execute=1
>
> cgControl, Output='overplots.png'
>
> END
>
> ;--------------------------------------------------------
>
>
>
> Create the cgWindow, turn updating off while you add a bunch of
>
> commands. Then turn window updating on and create the output.
>
>
>
> Cheers,
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Sorry, I forgot to mention that the included code was in a procedure and the main program had
cgWindow, 'Plot_DAQ_Trajectories', wbackground='white', wxsize=600, wysize=500, wtitle='Westerly Flow'
I still have several questions and some clarification though. In your example using cgWindow, you use cgPlot to begin. When I try to apply this to my code I get data plotted but no map background because cgPlot doesn't allow map=mapCoord. Is this correct or do I have things in the wrong order.
Also, to clarify. Once I have completed the loop, what I need to do is rerun the entire code with a new dataset going through the same calculations and plotting loop. At the moment this creates a new window, but I want to put in the same window as the first time I ran the code. Is this possible? Thanks.
-Morgan
|
|
|
Re: Overplot cgplots in graphics window [message #86339 is a reply to message #86338] |
Mon, 28 October 2013 10:25   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Morgan Silverman writes:
> Sorry, I forgot to mention that the included code was in a procedure
and the main program had
> cgWindow, 'Plot_DAQ_Trajectories', wbackground='white', wxsize=600, wysize=500, wtitle='Westerly Flow'
>
> I still have several questions and some clarification though. In your example using cgWindow, you use cgPlot to begin. When I try to apply this to my code I get data plotted but no map background because cgPlot doesn't allow map=mapCoord. Is this correct or do I have things in the wrong order.
Well, you have the wrong command. If you are not using a line plot, then
you wouldn't use the cgPlot command. :-)
You seem to be using a cgMap object. So, I would try something like
this:
map = Obj_New('cgMap', ..., /AddCmd)
Where "...", of course, includes all the usual things you put into the
command.
> Also, to clarify. Once I have completed the loop, what I need to do is rerun the entire code with a new dataset going through the same calculations and plotting loop. At the moment this creates a new window, but I want to put in the same window as the first time I ran the code. Is this possible? Thanks.
Every time you call cgWindow, it creates a new graphics window. If this
is not what you want, then check to see if that window is on the
display, and, if it is, use it, rather than creating a new window.
wids = cgQuery(TITLE=titles, COUNT=count)
IF count NE 0 THEN BEGIN
index = Where(StrUpCase(titles) EQ 'Plot_DAQ_Trajectories', tcnt)
ENDIF ELSE tcnt = 0
IF tcnt EQ 0 THEN BEGIN
cgWindow, WTitle='Plot_DAQ_Trajectories', wxsize=600, wysize=500
ENDIF ELSE BEGIN
cgSet, wids[index[0]]
ENDELSE
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: Overplot cgplots in graphics window [message #86340 is a reply to message #86339] |
Mon, 28 October 2013 10:42   |
morganlsilverman
Messages: 46 Registered: February 2013
|
Member |
|
|
On Monday, October 28, 2013 1:25:42 PM UTC-4, David Fanning wrote:
> Morgan Silverman writes:
>
>
>
>> Sorry, I forgot to mention that the included code was in a procedure
>
> and the main program had
>
>> cgWindow, 'Plot_DAQ_Trajectories', wbackground='white', wxsize=600, wysize=500, wtitle='Westerly Flow'
>
>>
>
>> I still have several questions and some clarification though. In your example using cgWindow, you use cgPlot to begin. When I try to apply this to my code I get data plotted but no map background because cgPlot doesn't allow map=mapCoord. Is this correct or do I have things in the wrong order.
>
>
>
> Well, you have the wrong command. If you are not using a line plot, then
>
> you wouldn't use the cgPlot command. :-)
>
>
>
> You seem to be using a cgMap object. So, I would try something like
>
> this:
>
>
>
> map = Obj_New('cgMap', ..., /AddCmd)
>
>
>
> Where "...", of course, includes all the usual things you put into the
>
> command.
>
>
>
>> Also, to clarify. Once I have completed the loop, what I need to do is rerun the entire code with a new dataset going through the same calculations and plotting loop. At the moment this creates a new window, but I want to put in the same window as the first time I ran the code. Is this possible? Thanks.
>
>
>
> Every time you call cgWindow, it creates a new graphics window. If this
>
> is not what you want, then check to see if that window is on the
>
> display, and, if it is, use it, rather than creating a new window.
>
>
>
> wids = cgQuery(TITLE=titles, COUNT=count)
>
> IF count NE 0 THEN BEGIN
>
> index = Where(StrUpCase(titles) EQ 'Plot_DAQ_Trajectories', tcnt)
>
> ENDIF ELSE tcnt = 0
>
> IF tcnt EQ 0 THEN BEGIN
>
> cgWindow, WTitle='Plot_DAQ_Trajectories', wxsize=600, wysize=500
>
> ENDIF ELSE BEGIN
>
> cgSet, wids[index[0]]
>
> ENDELSE
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
That's exactly what I needed. IDL really can do everything as long as you know how to do it :-) Thanks.
-Morgan
|
|
|
|