How to adjust legend
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Juan Camilo Medina
le 5 Mar 2013
Modifié(e) : Juan Camilo Medina
le 5 Mar 2013
"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 commentaires
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!