Skip to content

docs - plot - legend capture warning #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danton267 opened this issue Oct 23, 2021 · 1 comment
Closed

docs - plot - legend capture warning #452

danton267 opened this issue Oct 23, 2021 · 1 comment

Comments

@danton267
Copy link
Member

load accidents
x = hwydata(:,14); %Population of states
y = hwydata(:,4); %Accidents per state

X = [ones(length(x),1) x];
b = X\y;

yCalc2 = X*b;
plot(x,yCalc2,'--');
legend('Data','Slope','Slope & Intercept','Location','best');

fig2plotly(gcf);

yields following error

Warning: Ignoring extra legend entries. 
> In legend>process_inputs (line 587)
In legend>make_legend (line 315)
In legend (line 259)
In temp (line 10) 
@gilbertogalvis
Copy link
Contributor

gilbertogalvis commented Oct 23, 2021

That error you report is caused by MATLAB but not by matlab_plotly. This is because you are not using the MATLAB legend function correctly. You are passing the parameters wrong when you invoke legend.

Since you have a single plot line, you can only pass one label in legend, which would be 'Data' or 'Slope' or 'Slope & Intersection'. But you can't go through three because the chart doesn't have three traces.

The correct use would be the following

load accidents
x = hwydata(:,14) %Population of states
y = hwydata(:,4) %Accidents per state

X = [ones(length(x),1) x];
b = X\y;

yCalc2 = X*b
plot(x,yCalc2,'--');
legend({'Data'},'Location','best');

fig2plotly(gcf);

result will be

Screen Shot 2021-10-23 at 12 32 43 PM

Data+Slope

If you want to plot both the data and the slope, you need to do the following

load accidents
x = hwydata(:,14) %Population of states
y = hwydata(:,4) %Accidents per state

X = [ones(length(x),1) x];
b = X\y;

yCalc2 = X*b
plot(x,y,'o');
hold on
plot(x,yCalc2,'--');
legend({'Data', 'Slope'},'Location','best');

fig2plotly(gcf);

Screen Shot 2021-10-23 at 12 39 58 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants