Skip to content
This repository was archived by the owner on Apr 5, 2019. It is now read-only.

Error when passing empty legend handle #9

Open
sco1 opened this issue Oct 4, 2016 · 1 comment
Open

Error when passing empty legend handle #9

sco1 opened this issue Oct 4, 2016 · 1 comment

Comments

@sco1
Copy link
Member

sco1 commented Oct 4, 2016

MATLAB throws an error when attempting to utilize some legtools methods with an empty legend handle. This is due to the implicit assumption that the methods are being called on a non-empty legend handle.

For example:

% Set up figure
x = 1:10;
y1 = x;
figure
plot(x, y1);
lh = legend;

% Add box
dim = [0.4 0.4 0.2 0.2];
annotation('rectangle', dim, 'Color', 'red')

% Add a legend entry
legtools.adddummy(lh, 'A Red Rectangle', {'Color', 'red'})

Throws an uncaught error:

Expected one output from a curly brace or dot indexing expression, but there were 0 results.

Error in legtools.adddummy (line 179)
            parentaxes = lh.PlotChildren(1).Parent;

Error in testcode (line 13)
legtools.adddummy(lh, 'A Red Rectangle', {'Color', 'red'})

See: #7

@sco1 sco1 added the bug label Oct 4, 2016
@sco1 sco1 self-assigned this Oct 4, 2016
@sco1
Copy link
Member Author

sco1 commented Oct 5, 2016

The current behavior is correct-ish. Depending on the MATLAB release (>= R2014b), a "blank" legend() will be either a matlab.graphics.illustration.Legend object or matlab.graphics.GraphicsPlaceholder object. So they're both technically empty legends.

However, both append and adddummy should be able to add legend entries to an empty legend, so this will be added soon(ish).

@sco1 sco1 removed their assignment Apr 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant