how i can group legend from graphic made by plot and boxplot
6 views (last 30 days)
Show older comments
i'm trying to superpose two graphic made by plot and boxplot functions. this is an example:
if true
% code
clear
%data
p=[0.9 1.1 1.9 2.1 2.9 3.1];
p1=[0.9 1.9 2.9];
p2=[1.1 2.1 3.1];
data1=rand(10,3);
data2=rand(10,3);
data=[0.4 0.2 0.5 0.6 0.7 0.9];
%boxplot
h1=boxplot(data1, 'positions', p1, 'labels', p1)
hold on
h2=boxplot(data2, 'positions', p2, 'labels', p2)
%box style
set(h2,'LineStyle','-.')
%plot
b=plot(p,data,'LineStyle',':')
%legend
legend('type1','type2','plot')
hold off
end
i have this message
if true
% codeWarning: Ignoring extra legend entries.
> In legendHGUsingMATLABClasses>set_children_and_strings (line 650)
In legendHGUsingMATLABClasses>make_legend (line 313)
In legendHGUsingMATLABClasses (line 241)
In legend (line 118)
In exemple3 (line 20)
end
0 Comments
Answers (1)
Renato Agurto
on 17 Dec 2015
Hello, since boxplot returns more than one handler, you could use this to select only one of them:
legend([h1(1,1), h2(1,1), b], 'type1','type2','plot')
you can replace h1(1,1) with, h1(3,2) etc
Cheers
0 Comments
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!