Is this possible?
I wish this would work!
set(lgnd,'FaceAlpha','0.5')
Brian,
I couldn't find a straight-forward way to do it, but here is a workaround:
xi=linspace(0,1,20);
yi=xi;
figure
plot(xi,yi)
set(gca,'color','k')
leg=legend('line');
set(leg,'box','off')
ch=findall(leg,'type','axes');
ah=annotation('rectangle',get(ch,'position'));
set(ah,'facecolor','w','facealpha',0.5);
uistack(leg,'top')
-Andrew
Thank you so much for the help, this works well for a single plot, but for subplots I'm having some issues. Only the last subplot gets the uistack(handle,'top') function call.
How did you know to access the legend in the way you did with findall and annotation? Is there documentation out there on your technique? I found this: http://www.mathworks.com/help/techdoc/creating_plots/braliom.html , however I'm really confused as how it works.
For instance:
-------------------------------------- CODE ----------------------------
hAnnotation = get(legend_handle,'Annotation'),
hLegendEntry = get(hAnnotation','LegendInformation')
-------------------------------------- WORKSPACE ------------------
??? Error using ==> get
There is no 'Annotation' property in the 'legend' class.
Regards,
Brian
Thank you so much for your help. This works great for a single plot, but for multiple legends in subplots I'm having issues with uistack(handle,'top'); every legend but the last has the legend font below the 50% opaque box. Any suggestions?
Also how did you know to access the legend in the manner you did? Is there any documentation? I've been looking for a way to access legend properties, found this: http://www.mathworks.com/help/techdoc/creating_plots/braliom.html, but it didn't lead me to a way of assigning the background FaceAlpha.
Thanks,
Brian
Brian,
There is no facealpha property for a legend, so my workaround is basically making the axes if the legend invisible and putting a transparent patch (annotation) underneath the legend text. I used annotation instead of a patch object because it's position property is specified in figure units as is the legend. Anyway, to access the legend properties, just:
lh=legend(...)
The handle looks like an axes handle and has children to all the elements (lines, text, ect), all of which can be modified through the command, set. Not sure about documentation, but hope this helps.
Andrew
Thank you for your input. If I could get this to work in subplots it would look really good, however for the mean time I'm going to begrudgingly use this function in the file exchange: http://www.mathworks.com/matlabcentral/fileexchange/31092-legendflex-a-more-flexible-legend to position the legend above the subplots.
Thanks again for taking the time to help me out!
-Brian