声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1835|回复: 0

[绘图技巧] matlab中legend的用法

[复制链接]
发表于 2016-5-10 09:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x

用Matlab画图时,有时候需要对各种图标进行标注,例如,用“+”代表A的运动情况,“*”代表B的运动情况。

legend函数的基本用法是

LEGEND(string1,string2,string3, ...)

分别将字符串1、字符串2、字符串3……标注到图中,每个字符串对应的图标为画图时的图标。

例如:

plot(x,sin(x),'.b',x,cos(x),'+r')

legend('sin','cos')这样可以把"."标识为'sin',把"+"标识为"cos"

还可以用LEGEND(...,'Location',LOC) 来指定图例标识框的位置

这些是Matlab help文件。后面一段是对应的翻译和说明

  1.   'North'              inside plot box near top
  2.         'South'              inside bottom
  3.         'East'               inside right
  4.         'West'               inside left
  5.         'NorthEast'          inside top right (default)
  6.         'NorthWest           inside top left
  7.         'SouthEast'          inside bottom right
  8.         'SouthWest'          inside bottom left
  9.         'NorthOutside'       outside plot box near top
  10.         'SouthOutside'       outside bottom
  11.         'EastOutside'        outside right
  12.         'WestOutside'        outside left
  13.         'NorthEastOutside'   outside top right
  14.         'NorthWestOutside'   outside top left
  15.         'SouthEastOutside'   outside bottom right
  16.         'SouthWestOutside'   outside bottom left
  17.         'Best'               least conflict with data in plot
  18.         'BestOutside'        least unused space outside plot

  19.         'North'             图例标识放在图顶端
  20.         'South'            图例标识放在图底端
  21.         'East'               图例标识放在图右方
  22.         'West'              图例标识放在图左方
  23.         'NorthEast'       图例标识放在图右上方(默认)
  24.         'NorthWest      图例标识放在图左上方
  25.         'SouthEast'      图例标识放在图右下角
  26.         'SouthWest'     图例标识放在图左下角
  27. (以上几个都是将图例标识放在框图内)
  28.         'NorthOutside'          图例标识放在图框外侧上方
  29.         'SouthOutside'         图例标识放在图框外侧下方
  30.         'EastOutside'           图例标识放在图框外侧右方
  31.         'WestOutside'          图例标识放在图框外侧左方
  32.         'NorthEastOutside'   图例标识放在图框外侧右上方
  33.         'NorthWestOutside' 图例标识放在图框外侧左上方
  34.         'SouthEastOutside'   图例标识放在图框外侧右下方
  35.         'SouthWestOutside' 图例标识放在图框外侧左下方
  36. (以上几个将图例标识放在框图外)
  37.         'Best'                      图标标识放在图框内不与图冲突的最佳位置
  38.         'BestOutside'           图标标识放在图框外使用最小空间的最佳位置
  39. 还是用上面的例子
  40. legend('sin','cos','location','northwest')可以将标识框放置在图的左上角。
复制代码

转自:http://blog.sina.com.cn/s/blog_6f16b5970101pzzq.html


回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-4-24 12:53 , Processed in 0.176237 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表