Matlab科学作图中legend的格式,字体,方向,边框,位置,显示方式如下:
legend('\fontname{Times New Roman}USA', '\fontname{宋体}中国');多种字体组合
h0=legend('\it{data}','\rm{20%}\it{ error limit}','location','northeast');
legend('Origin(>90°)','data1','Fontsize',40,'FontName','Times New Roman','box','off');%取消边框
lgd.BoxFace.ColorType='truecoloralpha';%透明度
legend({'sin(x)', 'cos(x)'},'Location','best','EdgeColor','b','LineWidth',2);%设置边框颜色为蓝色,边框线宽为2
legend('$$y=e^{1.1x}$$','$$y=e^{1.3x}+100$$','Interpreter','latex','Location','northwest','Fontsize',15,'box','off')% 设置图例,字体latex,公式字体
legend({'sin(x)', 'cos(x)'}, 'Orientation', 'horizontal') % 水平方向图例
legend({'sin(x)', 'cos(x)'}, 'Orientation', 'vertical') % 垂直方向图例
legend('NumColumns', 2);% 添加图例并设置列数为2
legend('Location', 'Best'); % 设置图例位置为最佳位置
legend('Position', [0.2, 0.2, 0.2, 0.2]);%将在图的相对位置为(0.2, 0.2)的地方显示一个宽度为0.2,高度为0.2的图例
plot(x,y,'r','LineWidth',2,'HandleVisibility','off');%画不需要图例的线条
legend('boxoff') % 取消图例边框
位置常用如下
‘north’:位于图的上方中心位置。
‘south’:位于图的下方中心位置。
‘east’:位于图的右侧中心位置。
‘west’:位于图的左侧中心位置。
‘northeast’:位于图的右上方位置。
‘northwest’:位于图的左上方位置。
‘southeast’:位于图的右下方位置。
‘southwest’:位于图的左下方位置。
‘best’:自动选择最佳位置。
‘NorthOutside’
‘SouthOutside’
‘EastOutside’
‘WestOutside’
‘NorthEastOutside’
‘NorthWestOutside’
‘SouthEastOutside’
‘SouthWestOutside’
‘BestOutside’