例如现在有两条曲线,需要添加图例,添加的图例默认位置为图右上角,指令如下所示
legend('legend1','legend2')
如果想放到右下角,则可更改Location为southeast,如下所示。(方位为上北下南左西右东)
legend('legend1','legend2','Location','southeast')
值及说明如下所示
值 | 说明 |
'north' | 坐标区中的顶部 |
'south' | 坐标区中的底部 |
'east' | 坐标区中的右侧区域 |
'west' | 坐标区中的左侧区域 |
'northeast' | 坐标区中的右上角(二维坐标区的默认值) |
'northwest' | 坐标区中的左上角 |
'southeast' | 坐标区中的右下角 |
'southwest' | 坐标区中的左下角 |
'northoutside' | 坐标区的上方 |
'southoutside' | 坐标区的下方 |
'eastoutside' | 到坐标区的右侧 |
'westoutside' | 到坐标区的左侧 |
'northeastoutside' | 坐标区外的右上角(三维坐标区的默认值) |
'northwestoutside' | 坐标区外的左上角 |
'southeastoutside' | 坐标区外的右下角 |
'southwestoutside' | 坐标区外的左下角 |
'best' | 创建图例时坐标区内与绘图数据冲突最小的位置。如果绘图数据发生变化,您可能需要将位置重置为 'best' 。 |
'bestoutside' | 坐标区的右上角之外(当图例为垂直方向时)或坐标区下方(当图例为水平方向时) |
'layout' | 分块图布局中的图块。要将图例移至不同图块,请设置图例的 Layout 属性。 |
'none' | 由 Position 属性决定。可使用 Position 属性在自定义位置显示图例。 |
参考链接 https://ww2.mathworks.cn/help/releases/R2021b/matlab/ref/legend.html