1) By default, the Legend Tag
property is Legend. Of course, there are no promises that he will not change.
get(l) .... BusyAction: 'queue' HandleVisibility: 'on' HitTest: 'on' Interruptible: 'off' Selected: 'off' SelectionHighlight: 'on' **Tag: 'legend'** Type: 'axes' UIContextMenu: 200.0018 UserData: [1x1 struct] ....
2) Another difference (more reliable) is that ordinary axes do not have the String
property, but legends. I'm not sure if there are other objects that also have a String
property. For instance:
plot(magic(3));legend('a','v','b'); allAxesInFigure = findall(f,'type','axes') b = isprop(allAxesInFigure,'String')
You can verify this by calling:
get (GCA, 'String')
??? Error using ==> get There is no String property in the "axes" class.
But, on the other hand, for legends there is such a property. That is why it is more reliable.
plot(magic(3)); l = legend('a','b','c'); get(l,'String')
ans = 'a' 'b' 'c'
3) I would recommend solving this in a wider context. Just keep an eye on the legends and axes you create while keeping their pens. That is, instead of coding, for example:
plot(magic(3)); legend('a','v','b'); plot(magic(5)); legend('a','v','b','c','d');
Code like this:
p(1) = plot(magic(3)); l(1) = legend('a','v','b'); p(2) = plot(magic(5)); l(2) = legend('a','v','b','c','d');