[英]Matlab: variable legend in plot
我有一个图,其中绘制了可变数量的点(类似于网络的节点)和三个轨迹。 当我调用legend
也会获得轨迹的o
符号(对应于节点)。
我知道这是因为legend
函数需要为每个标签添加一个字符串,但是由于我不知道“先验”节点的总数(因为它是用户定义的参数),因此有一种方法可以指定能够正常地标记轨迹时,仅将节点标记为o
?
您只需要准确告诉legend
您想要什么即可。
轨迹:
t(1) = plot( xvector1, yvector1, linspecs ...)
t(2) = plot( xvector2, yvector2, ...)
...
t(n) = plot( xvectorn, yvectorn, ...)
及其标签:
tLabel{1} = 'trajectory label #1'
...
tLabel{n} = 'trajectory label #n'
节点相同:
p(1) = plot( x1, y1, 'o',...)
p(2) = plot( x2, y2, 'o',...)
...
p(m) = plot( xm, ym, 'o',...)
pLabel{1} = 'node label #1'
...
pLabel{m} = 'node label #m'
最终绘制了图例:
lh = legend( [traj(1:n),p(1:m)] , tLabel{1:n}, pLabel{1:m} );
当然,如果所有节点都具有相同的名称和样式,则只需使用节点数组的第一个条目:
lh = legend( [traj(1:n),p(1)] , tLabel{1:n}, pLabel{1} );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.