Help with legend children handles

9 visualizaciones (últimos 30 días)
Juan P. Viera
Juan P. Viera el 28 de En. de 2014
Comentada: José-Luis el 30 de En. de 2014
So I needed to change the style/color/symbol of the legend entries. I found out that (in normal conditions) for each legend entry there are 3 children handles, the first is the marker, second is the line, and third is the text. So I get these 3 handles this way:
Hchilds = get(hleg,'Children'); % Where hleg is the legend handle.
So when everything is working normal I can access the legend graphic objects and edit as desired in order to control the legend as I please.
I do this inside a group of plotting functions that I call and so on, but, SOMETIMES (don't know exactly what triggers this behavior), while I am calling this SAME set of functions repeatedly (trying out different plot settings for instance), suddenly there are not 3 children handles for each entry in the legend, but 8. My very vague guess is that, somewhere along the many functions I call, something triggers an option or something that changes the legend (or axes) behavior.
Inside the axes properties I have (for a plot with just 1 line) 8 children instead of the normal 1 I should have. I can't trace the problem easily since I think it can happen calling the same set of functions X number of times. A number of calls will go alright and then suddenly this changes and my function that changes legend looks crashes because its treating a text handle as a line handle (since the order in the handles is not right anymore).
A solution I found was to get the legend children handles through:
Hchilds = legprop.UserData.LabelHandles; % (here I do have 3 handles per legend entry even when the thing is behaving strangely)
Where legprop = get(hleg); % Where hleg is the legend handle.
But I thought the first approach was more appropiate or direct, and, although the solution I found seems to work, I would like (out of curiosity and not to lose faith) what is going on.
I know I should post code but the thing is the whole code is a lot more complicated than the actual problem, and what is curious is that the problem triggers while I am still calling the same routine over and over. Once this weird behavior is triggered, the complete Matlab session will behave this way (until I restart the whole program) even if I do "clear all", "close all", clc, everything. Once triggered, I get 8 children when running this:
plot(1:10); hleg = legend('L1'); hch = get(hleg,'Children');
And then, length(hch) is 8 instead of 3.
What I hope is that maybe someone that knows a lot about these things maybe says "hey, these are hidden handles that appear when you put option X in manual" or something like it.
Thanks in advance and sorry if the post is confusing.
JP
  5 comentarios
Juan P. Viera
Juan P. Viera el 30 de En. de 2014
I know that when you add entries to the legend, you get more handles. I said above that in normal conditions, for each entry in the legend you get 3 handles. Now, the problem is that something is triggering the 'ShowHiddenHandles' option because suddenly I get 8 handles PER legend entry. And maybe it is some built in function because in none of the lines I am running this occurs. What is even more weird is that, if it is some built in function, it is doing it randomly because the behavior gets triggered sometimes and sometimes not, with me running the same programs.
José-Luis
José-Luis el 30 de En. de 2014
It would be easier to help you with a minimum working example.

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by