How do i select data to legend in a plot ?
조회 수: 27 (최근 30일)
이전 댓글 표시
Hello,
I didn't find the way to legend the data as i want. A little code to explain :
data1=10*ones(10,4)+randn(10,4);
t1=(0:1:9);
figure();
plot(t1,data1,'bo');
hold on
data2=25*ones(100,4)+2*randn(100,4);
t2=(0:0.1:9.9);
plot(t2,data2,'rx');
legend([{'From data1'},{'From data2'}]);
And I want to create a legend which say "Blue circle are from the data1" and "Red cross from the data2", in two lines.
Here, both text refers to blue circle - data1 -, i think it's normal since there is four plot of data1. If a put four {'From data1'} cells, the last one is a red cross, but i don't want to have a big legend.
Does anybody know how to display only one label per group (with good marks) ?
댓글 수: 0
채택된 답변
Mischa Kim
2014년 5월 14일
편집: Mischa Kim
2014년 5월 14일
Blaise, use
data1 = 10*ones(10,4)+randn(10,4);
t1 = (0:1:9);
figure();
p1 = plot(t1,data1,'bo');
hold on
data2 = 25*ones(100,4)+2*randn(100,4);
t2 = (0:0.1:9.9);
p2 = plot(t2,data2,'rx');
legend([p1(1),p2(1)],'From data1','From data2');
The issue here is that the first plot already contains four data sets. With two legend entries you only get a legend for the first two data sets in the first plot, which is why they are both marked the same, with a blue circle.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!