How to adjust legend
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Juan Camilo Medina
el 5 de Mzo. de 2013
Editada: Juan Camilo Medina
el 5 de Mzo. de 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 comentarios
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!