Matlab中图例标记的高级自定义 [英] advanced customization of legend markers in matlab

查看:102
本文介绍了Matlab中图例标记的高级自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在matlab图例中对标记添加基本修改相对简单.以下代码段产生的图例():

It is relatively simple to add basic modifications to markers in matlab legends. The legend produced by the following code snippet ():

hold on h = plot(inf,inf,'ob',inf,inf,'r+'); legend(h,'Data1','Data2');

hold on h = plot(inf,inf,'ob',inf,inf,'r+'); legend(h,'Data1','Data2');

可以轻松修改为:,使用以下代码:

Can be easily modified to: using the following code:

[~,~,icons,~] = legend(h,'Data1','Data2'); set(icons(1),'LineStyle','-') set(icons(2),'LineStyle','-')

[~,~,icons,~] = legend(h,'Data1','Data2'); set(icons(1),'LineStyle','-') set(icons(2),'LineStyle','-')

但是,如果我想正确地说明诸如(圆圈不在一行中间)或(多种颜色一行上带有"+"标记的行).我没有找到任何属性或变通办法来修改图例框中标记的位置,或在一个图例组中添加多个标记.

However things become fairly complicated if I want to correctly legend objects such as (circle is not in the middle of a line) or (several colors for one line with '+' markers on it). I have not found any property or workaround that allows to modify the position of the markers in the legend box, or add several markers in one legend group.

有人知道包含用于图例自定义的高级信息的文档吗?还是如何更好地利用matlab提供的图形对象的众多属性来实现上述功能?

Does anyone know of a document that contains advanced information for legend customization? Or how to better use the numerous properties of graphic objects provided by matlab to achieve what is described above?

推荐答案

R2014a之前的MatLab版本中,legend框实际上是axes,因此通过其句柄修改其内容相对容易.

In the MatLab version up to R2014a the legend box is actually an axes so it is relatively easy to modify its content through its handle.

从版本R2014b开始,legendgraphics object,似乎无法访问轴句柄(请参考

From version R2014b the legend is a graphics object and seems there is no way to access to the axes handle (ref. to this post on undocumentedmatlab).

至R2014a

给出图例中两行的图例:

Given the legend for two lines in a plot:

h = plot((0:.1:2*pi),sin((0:.1:2*pi)),'ob',(0:.1:2*pi),cos((0:.1:2*pi)),'r+');
[a,b,icons,c] = legend(h,'Data1','Data2');

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆