필터 지우기
필터 지우기

How to adjust legend

조회 수: 1 (최근 30일)
Bas  Buddendorf
Bas Buddendorf 2013년 3월 4일
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

답변 (1개)

Juan Camilo Medina
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.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by