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

Home » Public Forums » archive » Re: Legend for plot
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: Legend for plot [message #68114 is a reply to message #67975] Wed, 16 September 2009 19:57 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Sep 16, 2:49 am, "b.a" <u4565...@anu.edu.au> wrote:
> What I mean, is to have the plot (and oplots) and the legend inside
> one window in my GUI. Actually my interface has several parts and one
> is a widget draw that will contain all the curves to be plotted. The
> problem is that when each curve is plotted, even though they have
> different colours, it is not clear which one is which. So I have to
> place a legend in there. I can't really use XYOUTS because I might
> have several plots which interrupt each other and I don't know where
> to place the XYOUTS :(
>
> Is it at all possible to place a legend inside a widget_draw which
> contains plots? The code that you wrote is what I want plus I need to
> put the plots in the same window.
>
> Thanks a lot.

Ok, now your initial question is more clear: how to put a legend into
your plot in the draw widget. You can go about it with object graphics
or direct graphics. I do not remember if there is a built in way to do
it in direct graphics (have not used them in years), but I know there
is a routine for that in IDLAstro (http://idlastro.gsfc.nasa.gov/),
though doing that way still required you to keep track of which lines/
symbols/colors were used on each plot, to use the same in the legend.

With object graphics, you can make and set yourself all the plot,
axes, symbols and legends, or use iplot to make the plots and put the
legends in them, then copy its view object to your draw widget. Taking
your example, it would be something like:

pro demolegend

x1 = [1,2,3,4,5]
y1 = [4,5,6,7,8]

x2 = [2,3,4,4.5,5]
y2 = [4,5,6,7,8]

tlb = Widget_Base(column=1, XSIZE=350, YSIZE= 400,$
XOFFSET=250, YOFFSET= 300)

dr_window = WIDGET_DRAW(tlb, UVALUE= 'draw', $
XSIZE= 348, YSIZE=200, GRAPHICS_LEVEL = 2)

Widget_Control, tlb, /realize
WIDGET_CONTROL, dr_window, GET_VALUE = mywindow

;make the plots in an invisible itool
iplot,y2,x2,color=[255,0,0],name='one ',insert_legend=[0.,0.],$
dimensions=[348,200],$
/no_saveprompt,/disable_splash,user_interface='none'
iplot,y1,x1,color=[0,0,255],name='two ',/insert_legend,/over
;get the itool object
id=itgetcurrent(tool=ot)
;unselect the currently selected object, if any
osel=ot->getselecteditems(count=nosel,/all)
for i=0,nosel-1 do osel[i]->select,/unselect
;get the view object from the itool (assuming all ploting has been
done)
myview=ot->getbyidentifier(ot->findidentifiers('*/WINDOW/VIEW_1'))
mywindow->Draw, myview
;close the itool
itdelete,id

Xmanager, 'demolegend', tlb

end

Note that the legend is not being created by this program, it is made
by iplot.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL on the web?
Next Topic: iplot colorbar label

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

Current Time: Sat Oct 11 20:17:55 PDT 2025

Total time taken to generate the page: 0.08348 seconds