How to adjust legend
4 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have a matrix M of which I have made a plot. However, the first 8 columns belong to a certain class (where Degree==1 and it uses only those columns for which this is true and does this for the whole matrix of 20 columns) I have given the columns belonging to the same class the same colour, now I want to have my legend displaying only those four classes (with a category name) instead of all 20 lines. Here is my code:
figure(1), clf('reset'),
plot(HMAX,R_time(:,Degree==1),'LineWidth',0.5,'Color','b');hold on
plot(HMAX,R_time(:,Degree==2),'LineWidth',0.5,'Color',[0 0.5 0]);
plot(HMAX,R_time(:,Degree==3),'LineWidth',0.5,'Color','r');
plot(HMAX,R_time(:,Degree==4),'LineWidth',0.5,'Color',[0 0.8 0.8]);
hold off
xlim([0.38 0.59]);
xlabel 'Hmax';
ylabel 'Time';
hget=get(gca,'title'); set(hget,'FontSize',20);
hget=get(gca,'xlabel'); set(hget,'FontSize',20);
hget=get(gca,'ylabel'); set(hget,'FontSize',20);
drawnow;
How can I can get a legend that only displays the four classes according to the colours I assigned?? Help is much appreciated!
Bas
0 件のコメント
回答 (1 件)
Juan Camilo Medina
2013 年 3 月 5 日
編集済み: Juan Camilo Medina
2013 年 3 月 5 日
"Legend" will label whatever has been drawn in your figure; therefore, you need to invoke the legend command right after you plotted whatever lines you want labeled, and before you plot the rest of the lines that you don't want labeled.
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!