problem with the legend in my graph

1 回表示 (過去 30 日間)
Sam Alex
Sam Alex 2012 年 12 月 25 日
Hi,
In the code below, the legend is not representative to the data stream being drawn and with different colors than what I specified. Could anyone plz tell what am I doing wrong?
x1=untitled(:,4);
x2=untitled(:,5);x3=untitled(:,6);
G=linspace(0,9999,length(x1));
G=G';
ii = round(linspace(1,numel(x1),50)) ; ix = round(linspace(1,numel(x2),50));ixx = round(linspace(1,numel(x3),50)) ;
plot(G,x1,'r-',G(ii),x1(ii),'r+');hold on;
plot(G,x2,'b-',G(ix),x2(ix),'bo');hold on; plot(G,x3,'k-',G(ixx),x3(ixx),'ks');hold on;xlabel('Function Evaluations (FE)');ylabel('log[f(x)-f(x~)]');legend('NCA','N-HCA','IN-HCA');title('Constrained function 1');
Thanks

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 25 日
編集済み: Azzi Abdelmalek 2012 年 12 月 25 日
Because you have six plots, the legend will correspond, in order, to the three first plot
Look how to do it
close
G=0:0.1:10
x1=sin(t);
x2=cos(t)
x3=sin(0.5*t)
ii=randi(numel(t),5,1)
% first three plot
plot(G,x1,'r-'),hold on
plot(G,x2,'b-')
plot(G,x3,'k-')
%last three plot
plot(G(ii),x1(ii),'r+');
plot(G(ii),x3(ii),'ks');
plot(G(ii),x2(ii),'bo');
xlabel('Function Evaluations (FE)');
ylabel('log[f(x)-f(x~)]');
legend('NCA','N-HCA','IN-HCA');
title('Constrained function 1');
  4 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 25 日
Sam, use hold on once, at the end use hold off. If you want your markers to apear in the legend, plot the last three plots then the first ones
Sam Alex
Sam Alex 2012 年 12 月 25 日
Azzi..a question, now when I do this it works fine, and the markers show fine, now when I convert to log y scale the markers are not much visible for some of the curves (that have negative values) as they are smaller but I want these markers still to be clear, any ideas?

サインインしてコメントする。

その他の回答 (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