How do i select data to legend in a plot ?

28 ビュー (過去 30 日間)
Blaise
Blaise 2014 年 5 月 14 日
編集済み: Mischa Kim 2014 年 5 月 14 日
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) ?

採用された回答

Mischa Kim
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 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by