comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How to access properties of multiple plots in a function graphics window?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: How to access properties of multiple plots in a function graphics window? [message #86490 is a reply to message #86488] Wed, 13 November 2013 09:31 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark Piper writes:

>
> On Tuesday, November 12, 2013 10:22:02 AM UTC-7, Paul van Delst wrote:
>>
>> What I want to do is access w and modify the properties of the various
>> plots (e.g. font size, legend font size) via the "w" object reference.
>>
>
> Hi Paul,
>
> You can access plot properties by NAME. For example, given:
>
> w = window()
> for i=0, 5 do begin
>
> !null = plot(/test, color=!color.(i), layout=[3,2,i+1], $
> current=w, name=string(i, format='(i2.2)'))
> endfor
>
> you can set the color of the fifth plot to red with:
>
> w['04'].color = 'red'

This is pretty useful. Especially if you know the name of the plot
(although unlikely in a widget program). I was curious just what was in
a window object (I assumed it was a container), so I wrote a small
program to give me back the contents of an object.

;----------------------------------------------------------- -----------
FUNCTION cgGetObjects, theObject, ISA=isa, COUNT=count

On_Error, 2

count = 0
IF Obj_HasMethod(theObject, 'GET') THEN BEGIN
contents = theObject -> Get(/ALL,COUNT=childCount)
ENDIF ELSE RETURN, !NULL

; If there is nothing in the container, return !NULL.
IF childCount EQ 0 THEN BEGIN
RETURN, !NULL
ENDIF

; Make this call recursively.
result = contents

FOR j=0,childCount-1 DO BEGIN
thisResult = cgGetObjects(contents[j], COUNT=count, ISA=isa)
IF count GT 0 THEN result = [result, thisResult]
ENDFOR

IF N_Elements(isa) NE 0 THEN BEGIN
indices = Where(Obj_ISA(result, isa), count)
IF count GT 0 THEN result = result[indices] ELSE result = !Null
ENDIF

count = N_Elements(result)
RETURN, result

END
;----------------------------------------------------------- -----------


Then, I found I could do this without knowing the name of anything.

win = window()
p1 = plot(cgdemodata(17), color='red', /current)
p2 = plot(cgdemodata(17), color='green', /overplot, /current)
objs = cgGetObjects(win, ISA='IDLGRPLOT')

Oddly, there are four plot objects in the window, not two. Maybe the
other two are used for backing store? Not sure about that. Maybe Mark
can help us understand this. But, in any case, there appear to be
duplicates. Oddly, I can't do this:

objs[0].color = 'blue'
objs[2].color = 'orange'

But, I can do this:

objs[0] -> SetProperty, Color=cgColor('navy', /Triple, /Row)
objs[2] -> SetProperty, Color=cgColor('orange', /Triple, /Row)
win.refresh

For what it is worth. :-)

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.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Array into binary array
Next Topic: PSYM=10 + POLYFILL = ?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:30:37 PDT 2025

Total time taken to generate the page: 0.00458 seconds