Why do I get “Ignoring extra legend entries” evein in such trivial case?
Hello everyone,
MATLAB never misses on destroying any confidence you have in you coding skills.
I am coding a relatively easy script for data analysis, where I would plot data with a legend. In the code, I loop a plot() function to stack lines and then I ask to display a legend. However, I get the classic error from MATLAB:
Warning: Ignoring extra legend entries.
> In legend>process_inputs (line 590)
In legend>make_legend (line 319)
In legend (line 263)
Without dumping here the entire code, which is redundant, I get the same warning in an analogous and much simpler case:
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:)); hold on
end
legend(Labs)
The result is 5 lines in the plot, but MATLAB throws the warning above, displaying an empty legend in the figure.
If I try instead the "DislayName" method, the warning disappears, but the legend doesn’t even show up.
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:), "DisplayName", Labs{i}); hold on
end
legend
Can someone please help make sense of this? Thank you very much in advance.Hello everyone,
MATLAB never misses on destroying any confidence you have in you coding skills.
I am coding a relatively easy script for data analysis, where I would plot data with a legend. In the code, I loop a plot() function to stack lines and then I ask to display a legend. However, I get the classic error from MATLAB:
Warning: Ignoring extra legend entries.
> In legend>process_inputs (line 590)
In legend>make_legend (line 319)
In legend (line 263)
Without dumping here the entire code, which is redundant, I get the same warning in an analogous and much simpler case:
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:)); hold on
end
legend(Labs)
The result is 5 lines in the plot, but MATLAB throws the warning above, displaying an empty legend in the figure.
If I try instead the "DislayName" method, the warning disappears, but the legend doesn’t even show up.
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:), "DisplayName", Labs{i}); hold on
end
legend
Can someone please help make sense of this? Thank you very much in advance. Hello everyone,
MATLAB never misses on destroying any confidence you have in you coding skills.
I am coding a relatively easy script for data analysis, where I would plot data with a legend. In the code, I loop a plot() function to stack lines and then I ask to display a legend. However, I get the classic error from MATLAB:
Warning: Ignoring extra legend entries.
> In legend>process_inputs (line 590)
In legend>make_legend (line 319)
In legend (line 263)
Without dumping here the entire code, which is redundant, I get the same warning in an analogous and much simpler case:
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:)); hold on
end
legend(Labs)
The result is 5 lines in the plot, but MATLAB throws the warning above, displaying an empty legend in the figure.
If I try instead the "DislayName" method, the warning disappears, but the legend doesn’t even show up.
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:), "DisplayName", Labs{i}); hold on
end
legend
Can someone please help make sense of this? Thank you very much in advance. legend, plot, loop MATLAB Answers — New Questions