Another idiosyncracy? [message #91942] |
Mon, 21 September 2015 16:19  |
laura.hike
Messages: 87 Registered: September 2013
|
Member |
|
|
Why on earth does IDL require you to set the position of a legend by specifying a location for the upper RIGHT corner? It's much easier to see the upper left corner, and you don't have to keep readjusting the location every time the length of the labels changes. The more I try to do in IDL, the more I think it's time to learn Python....
|
|
|
Re: Another idiosyncracy? [message #91943 is a reply to message #91942] |
Mon, 21 September 2015 16:35   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
laura.hike@gmail.com writes:
> Why on earth does IDL require you to set the position of a legend by specifying a location for the upper RIGHT corner? It's much easier to see the upper left corner, and you don't have to keep readjusting the location every time the length of the labels changes. The more I try to do in IDL, the more I think it's time to learn Python....
I think you are coming at this problem from a right-handed perspective.
Software developers, as is well known, are all left-handed. ;-)
Cheers,
David
P.S. Let's just say Coyote was right handed and he allowed you to
specify the left-hand corner, or any other damn location you wanted
(nine choices!), in cgLegend. :-)
--
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: Another idiosyncracy? [message #91945 is a reply to message #91943] |
Mon, 21 September 2015 19:39   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Monday, September 21, 2015 at 7:35:38 PM UTC-4, David Fanning wrote:
> P.S. Let's just say Coyote was right handed and he allowed you to
> specify the left-hand corner, or any other damn location you wanted
> (nine choices!), in cgLegend. :-)
And often one does not want to specify or know the numerical location of the legend, but rather one just wants to place the legend snug in a corner of the plot . Here's how to do this with the direct graphics procedure AL_LEGEND
IDL> cgplot,indgen(10)
IDL> al_legend,['This is a very long title'],lines=0,/right ;Place legend snug in upper right
IDL> al_legend,['short'],lines=1,/bottom,/right ;Place legend snug in lower right
|
|
|
Re: Another idiosyncracy? [message #91946 is a reply to message #91945] |
Mon, 21 September 2015 19:47   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
wlandsman writes:
>
> On Monday, September 21, 2015 at 7:35:38 PM UTC-4, David Fanning wrote:
>
>> P.S. Let's just say Coyote was right handed and he allowed you to
>> specify the left-hand corner, or any other damn location you wanted
>> (nine choices!), in cgLegend. :-)
>
> And often one does not want to specify or know the numerical location of the legend, but rather one just wants to place the legend snug in a corner of the plot . Here's how to do this with the direct graphics procedure AL_LEGEND
>
> IDL> cgplot,indgen(10)
> IDL> al_legend,['This is a very long title'],lines=0,/right ;Place legend snug in upper right
> IDL> al_legend,['short'],lines=1,/bottom,/right ;Place legend snug in lower right
In truth, Coyote probably stole most of the code from AL_Legend. He told
me once that almost all of his good ideas were first thought up at NASA.
;-)
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: Another idiosyncracy? [message #91950 is a reply to message #91942] |
Tue, 22 September 2015 03:23   |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Monday, September 21, 2015 at 8:19:20 PM UTC-3, laura...@gmail.com wrote:
> Why on earth does IDL require you to set the position of a legend by specifying a location for the upper RIGHT corner? It's much easier to see the upper left corner, and you don't have to keep readjusting the location every time the length of the labels changes. The more I try to do in IDL, the more I think it's time to learn Python....
I am not quite sure what you mean... Do you want a legend box that sits next to the left side? This would be the case requiring to change the coordinates with text length, if the coordinates are those of the right side.
Anyway, if you mean Function Graphics, you can choose whether the coordinates you give are those of the right or left side (or top or bottom, or center, or anywhere in between):
p=plot(/test,name='plot 1')
;put a legend box in the center:
l=legend(target=p,$
position=[0.5,0.5],/normal,horizontal_alignment=0.5,vertical _alignment=0.5)
;put a legend box in the top left:
l=legend(target=p,$
position=[0.0,1.0],/normal,horizontal_alignment=0.0,vertical _alignment=1.0)
;put a legend box in the top right:
l=legend(target=p,$
position=[1.0,1.0],/normal,horizontal_alignment=1.0,vertical _alignment=1.0)
;put a legend box in the bottom left:
l=legend(target=p,$
position=[0.0,0.0],/normal,horizontal_alignment=0.0,vertical _alignment=0.0)
;put a legend box in the bottom right:
l=legend(target=p,$
position=[1.0,0.0],/normal,horizontal_alignment=1.0,vertical _alignment=0.0)
Intermediate values for horizontal/vertical alignment allow for other possibilities. And there are aliases for the values 1.0 and 0.0: 'bottom', 'top', 'left' and 'right' (http://www.exelisvis.com/docs/LEGEND.html#HORIZONT)
|
|
|
Re: Another idiosyncracy? [message #91952 is a reply to message #91950] |
Tue, 22 September 2015 08:11   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Tuesday, September 22, 2015 at 6:23:37 AM UTC-4, Paulo Penteado wrote:
> Anyway, if you mean Function Graphics, you can choose whether the coordinates you give are those of the right or left side (or top or bottom, or center, or anywhere in between):
Thanks for pointing this out. So to modify the example at the beginning of the LEGEND documentation so that the legend is flush in the upper right corner, one could write
leg = LEGEND(TARGET=[plot1,plot2], POSITION=[plot1.xrange[1],plot1.yrange[1]], $
/DATA,horizontal_alignment='right',vertical_alignment='top')
--Wayne
|
|
|
Re: Another idiosyncracy? [message #91963 is a reply to message #91950] |
Wed, 23 September 2015 12:22   |
laura.hike
Messages: 87 Registered: September 2013
|
Member |
|
|
Thanks! These options work, but this approach is so not obvious to me from the documentation. Under "position," it says
"Set this property to set the location of the legend. POSITION is specified as a 2 element vector: [X, Y], defining the upper right corner of the legend. If the DEVICE property is set, the units are given in device units (pixels)."
OK, the location given refers to the upper right corner. For "vertical_alignment," which I originally thought applied to the text, not the box itself, it says
"The vertical alignment of the legend with respect to the position. This is a value between 0 and 1 where 1 specifies top aligned (the default)."
Given the prior statement, I have no idea what this means. After seeing your examples, I would say that the description of "position" is completely lacking. It should say "upper right" is the default, but that this can be changed using the "alignment" options.
How do you guys learn this stuff, a lot of trial and error? I really appreciate your help.
|
|
|
|