Manipulating individual legend label's text properties

6 views (last 30 days)
Jim
Jim on 15 Apr 2013
Hi. I have a figure with loads of lineseries plotted on it. I've added a ButtonDownFcn callback function that causes clicking on any series to blink the corresponding legend label a couple times by toggling its visibility. That works fine, but now I'd like to identify the selected series even more distinctively by temporarily changing its color to red, increasing its fontsize, and bolding it. Trouble is, when I do this, all the legend labels become bigger and bolder. Does anyone know how to change the fontsize and fontweight properties of a single label without changing all the others?
Here's the code:
function BlinkLegendText(~,~,legendTxt)
objTypes = get(objHdl,'type'); % this is an embedded callback so objHdl,
% which points to all the graphic objs in
% the legend, is in-scope
lblHdls = objHdls(strcmp(objTypes,'text'); % legend label text handles
myLblHdl = lblHdls(strcmp(get(lblHdls, 'string'), legendTxt);
origSz = get(myLblHdl, 'fontsize');
origClr = get(myLblHdl, 'color');
origWt = get(myLblHdl, 'fontweight');
The next line should only affect myLblHdl, but it actually modifies the fontsizes and weights of all the legend labels pointed to by lblHdls. Even more curiously, the color change affects only the intended label...
set(myLblHdl, 'fontsize',14,'color',[1 0 0],'fontweight','bold);
...

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!