From: Johannes Buechler on 6 Aug 2010 05:15 Hi, is there a way to retrieve the position and size of a legend that has been automatically placed by Matlab? Any hint would be appreciated. Thanks and best regards Johannes
From: Ross W on 6 Aug 2010 06:24 "Johannes Buechler" <jb_spam(a)gmx.DELnet> wrote in message <i3gjqr$9vd$1(a)fred.mathworks.com>... > Hi, > > is there a way to retrieve the position and size of a legend that has been automatically placed by Matlab? Any hint would be appreciated. > > Thanks and best regards > > Johannes Hi [legend_h,object_h,plot_h,text_strings] = legend(...) returns legend_h — Handle of the legend axes object_h — Handles of the line, patch, and text graphics objects used in the legend plot_h — Handles of the lines and other objects used in the plot text_strings — Cell array of the text strings used in the legend These handles enable you to modify the properties of the respective objects. For example, Pos=get(legend_h,'Position') Ross
From: Johannes Buechler on 6 Aug 2010 08:21 "Ross W" <rosswoodskiwi(a)hotmail.com> wrote in message <i3gns3$nvp$1(a)fred.mathworks.com>... > > [legend_h,object_h,plot_h,text_strings] = legend(...) returns > > legend_h — Handle of the legend axes > object_h — Handles of the line, patch, and text graphics objects used in the legend > plot_h — Handles of the lines and other objects used in the plot > text_strings — Cell array of the text strings used in the legend > > These handles enable you to modify the properties of the respective objects. > > For example, > Pos=get(legend_h,'Position') Thanks Ross, that works :-) Only it seems that the annotation box that I want to put underneath the legend (with a slight position shift) is always on top of the legend now. The Matlab help says annotations are created in a separate axes object. Do you happen to know whether it is somehow possible to send the annotations layer to the bottom? I could use the rectangular function instead, but then I can't use the Position information from the legend :-( The code that I am using is the following (Width and Height are from the figure window in normalized numbers and centimeters as unit, so 0.15/Width is always 1.5 mm): [legend_h,object_h,plot_h,text_strings] = legend(ax11, 'x', 'y', 'z'); LegendPos = get(legend_h,'Position'); ShadowPos = [(LegendPos(1)+ 0.15/Width), (LegendPos(2)-0.15/Height), LegendPos(3), LegendPos(4)]; LegendShadow = annotation('textbox'); set(LegendShadow, 'Position', ShadowPos, 'BackgroundColor', 'k'); Thanks Johannes
From: Ross W on 12 Aug 2010 16:29 "Johannes Buechler" <jb_spam(a)gmx.DELnet> wrote in message <i3gung$57s$1(a)fred.mathworks.com>... > "Ross W" <rosswoodskiwi(a)hotmail.com> wrote in message <i3gns3$nvp$1(a)fred.mathworks.com>... > > > > [legend_h,object_h,plot_h,text_strings] = legend(...) returns > > > > legend_h — Handle of the legend axes > > object_h — Handles of the line, patch, and text graphics objects used in the legend > > plot_h — Handles of the lines and other objects used in the plot > > text_strings — Cell array of the text strings used in the legend > > > > These handles enable you to modify the properties of the respective objects. > > > > For example, > > Pos=get(legend_h,'Position') > > Thanks Ross, that works :-) > > Only it seems that the annotation box that I want to put underneath the legend (with a slight position shift) is always on top of the legend now. The Matlab help says annotations are created in a separate axes object. Do you happen to know whether it is somehow possible to send the annotations layer to the bottom? > > I could use the rectangular function instead, but then I can't use the Position information from the legend :-( > > The code that I am using is the following (Width and Height are from the figure window in normalized numbers and centimeters as unit, so 0.15/Width is always 1.5 mm): > [legend_h,object_h,plot_h,text_strings] = legend(ax11, 'x', 'y', 'z'); > LegendPos = get(legend_h,'Position'); > ShadowPos = [(LegendPos(1)+ 0.15/Width), (LegendPos(2)-0.15/Height), LegendPos(3), LegendPos(4)]; > LegendShadow = annotation('textbox'); > set(LegendShadow, 'Position', ShadowPos, 'BackgroundColor', 'k'); > > Thanks > > Johannes Hi Though the annotation is in a separate axes object, I think you can still do what you want. It's just a little more work. Now you need to know where both your axes are located with respect to the figure, as well as where the legend and annotation are with respect to their axes. ax11Pos=get(ax11,'Pos'); annPos=get(LegendShadow ,'Pos'); Do you see what to do now? Ross
From: Johannes Buechler on 13 Aug 2010 03:59
"Ross W" <rosswoodskiwi(a)hotmail.com> wrote in message <i41lij$ce8> Now you need to know where both your axes are located with respect to the figure, as well as where the legend and annotation are with respect to their axes. > > ax11Pos=get(ax11,'Pos'); > annPos=get(LegendShadow ,'Pos'); > > Do you see what to do now? If I get you right, you suggest using an additional annotation box that replaces the original legend? That'd mean a lot of additional work - or did I get you wrong? If not: The position issue already works perfectly, the shadow box appears exactly where I want it, only it appears on top of the legend (thus hiding it for the most part) instead of behind. Thanks, Johannes |