MATLAB中legend用法小细节

 大家在用legend添加图例时有没有遇到过如下问题呢

“不支持使用整数来指定图例位置。请使用 'Location' 参数来指定图例相对于坐标轴的位置。”

根据之前的学习,是用数字参数来确定注释视窗在图形中的位置的,但是在2016b这个版本会出错(可能是高版本的原因),原来的参数集如下:

    参数字符串                                      含  义  

0                              尽量不与数据冲突,自动放置在最佳位置  

1                                                          放置在图形的右上角 

2                                                          放置在图形的左上角    

3                                                          放置在图形的左下角

4                                                          放置在图形的右下角    

-1                              放置在图形视窗的外右边    

查询帮助找到以下参数集:

Value

Description

'north'

Inside top of axes

'south'

Inside bottom of axes

'east'

Inside right of axes

'west'

Inside left of axes

'northeast'

Inside top-right of axes (default for 2-D axes)

'northwest'

Inside top-left of axes

'southeast'

Inside bottom-right of axes

'southwest'

Inside bottom-left of axes

'northoutside'

Above the axes

'southoutside'

Below the axes

'eastoutside'

To the right of the axes

'westoutside'

To the left of the axes

'northeastoutside'

Outside top-right corner of the axes (default for 3-D axes)

'northwestoutside'

Outside top-left corner of the axes

'southeastoutside'

Outside bottom-right corner of the axes

'southwestoutside'

Outside bottom-left corner of the axes

'best'

Inside axes where least conflict occurs with plot data

'bestoutside'

To the right of the axes

'none'

Determined by Position property. Use the Position property to display the legend in a custom location.

 有些小伙伴是不是直接复制过去了呢,哈哈,我当时也是这么做的。是会报错的哦!

大家在使用这些参数集之前记得声明一下'Location'哦,举个栗子(开头大写的Location,开头小写的northwest哦):

legend('实测值','预测值','Location','northwest')

这是对两个曲线的图形及进行图例注释。

在legend的帮助里还找到了下面的例子:

x = -pi:pi/20:pi;
           y1 = sin(x);
           plot(x,y1)

hold on
           y2 = cos(x);
           plot(x,y2,'--')
           hold off

legend('sin(x)','cos(x)','Location','northwest','Orientation','horizontal')

这个例程的结果如下图:

大家实践一下就会知道Orientation的神奇作用了~

  • 19
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值