Matlab Graphics: LegendsNotes:Legends are useful for labelling complicated plots. Their location can becontrolled.Example Script:% Script File: ShowLegend% How to position a legend.loc={’North’,’South’,’East’,’West’,...’NorthEast’ , ’NorthWest’ , ’SouthEast’ , ’SouthWest’ ,...’NorthOutside’ , ’SouthOutside’ , ’EastOutside’ , ’WestOutside’ ,...’NorthEastOutside’ , ’NorthWestOutside’ , ’SouthEastOutside’ ,...’SouthWestOutside’ , ’Best’ , ’BestOutside’ };close allt = linspace(0,2);axis([0 2 -1.5 1.5])y1 = sin(t*pi);y2 = cos(t*pi);plot(t,y1,t,y2,’--’,[0.511.52],[00000],’o’)set(gca,’XTick’,[])set(gca,’YTick’,[0])grid onfor k=1:length(loc)legend(’sin(\pi t)’,’cos(\pi t)’,’roots’,’location’,loc{k})title(’ ’)title(loc{k},’FontSize’,14)pauseendSample Output:0NorthEast sin(π t)cos(π t)roots0SouthOutside sin(π t)cos(π t)roots0NorthEastOutside sin(π t)cos(π t)roots0SouthWestOutside sin(π t)cos(π t)roots0Best sin(π t)cos(π t)roots0BestOutside sin(π t)cos(π
View Full Document