legend:
(resource:examples of legend in matlab document)
用法:
1.legend('string1','string2',...)
'string1','string2'按顺序对应图中曲线;
hleg1 = legend('cos_x','sin_x')将返回一个句柄hleg1
下划线后被识别为下标,可以通过句柄使用set(hleg1,'Interpreter','none')关闭解释器来避免;
通过句柄设置图例位置,具体位置有NorthEast、NorthWest、SouthWest、SouthEast,如:set(hleg1,'Location','NorthWest');
通过句柄设置图例位置与原图之外,参数为:NorthEastOutside、NorthWestOutside、SouthEastOutside、SouthWestOutside
或者通过句柄设置具体位置,如:set(hleg1, 'Position', [.1,.2,.1,.2])
通过句柄将字体设为斜体,颜色为棕,如:set(hleg1,'FontAngle','italic','TextColor',[.3,.2,.1]),三坐标分别代表红绿蓝;
2.legend(h,'string1','string2',...)使用别的句柄来指定要图例中出现顺序,如:
hb = bar(y1,'stacked');
hp = plot(1:10,y2); hold off
legend([hb,hp],'Carrots','Peas','Peppers','Green Beans', 'Cucumbers','Eggplant','Location','SouthEastOutside')