精华内容
下载资源
问答
  • Matlablegend默认的位置在NorthEast,如图所示:%Matlablegend位置设置clcclearclose allNpoint = 100;x = linspace(0,4*pi,Npoint);y1 = sin(x);y2 = cos(x);H = plot(x,y1,x,y2);legend('sin(x)','cos(x)');...

    Matlab中legend默认的位置在NorthEast,如图所示:

    %Matlab中legend的位置设置

    clc

    clear

    close all

    Npoint = 100;

    x = linspace(0,4*pi,Npoint);

    y1 = sin(x);

    y2 = cos(x);

    H = plot(x,y1,x,y2);

    legend('sin(x)','cos(x)');

    然而,我们却可以通过Location对legend的位置进行改变,变为North,如图所示

    %Matlab中legend的位置设置

    clc

    clear

    close all

    Npoint = 100;

    x = linspace(0,4*pi,Npoint);

    y1 = sin(x);

    y2 = cos(x);

    H = plot(x,y1,x,y2);

    legend('sin(x)','cos(x)','Location','North');

    Matlab位置选择

    设置

    位置

    'North'

    inside plot box near top

    'South'

    inside bottom

    'East'

    inside right

    'West'

    inside left

    'NorthEast'

    inside top right (default for 2-D plots)

    'NorthWest'

    inside top left

    'SouthEast'

    inside bottom right

    'SouthWest'

    inside bottom left

    'NorthOutside'

    outside plot box near top

    'SouthOutside'

    outside bottom

    'EastOutside'

    outside right

    'WestOutside'

    outside left

    'NorthEastOutside'

    outside top right (default for 3-D plots)

    'NorthWestOutside'

    outside top left

    'SouthEastOutside'

    outside bottom right

    'SouthWestOutside'

    outside bottom left

    'Best'

    least conflict with data in plot

    'BestOutside'

    least unused space outside plot

    Matlab中还可以选择某条曲线legend的指定显示

    %Matlab中legend的选择

    clc

    clear

    close all

    Npoint = 101;

    x = linspace(0,10,Npoint);

    y1 = besselj(1,x);

    y2 = besselj(2,x);

    y3 = besselj(3,x);

    y4 = besselj(4,x);

    y5 = besselj(5,x);

    H = plot(x,y1,x,y2,x,y3,x,y4,x,y5);

    legend('First','Second','Third','Fourth','Fifth','Location','NorthEastOutside')

    如果只想显示第1、3、5条,也很简单

    %Matlab中legend的选择

    clc

    clear

    close all

    Npoint = 101;

    x = linspace(0,10,Npoint);

    y1 = besselj(1,x);

    y2 = besselj(2,x);

    y3 = besselj(3,x);

    y4 = besselj(4,x);

    y5 = besselj(5,x);

    H = plot(x,y1,x,y2,x,y3,x,y4,x,y5);

    h1 = legend(H([1 3 5]),'First','Third','Fifthth','Location','NorthEastOutside')

    还可以使用Orientation对legend进行横向排列

    %Matlab中legend的横排,注意,Location位置改变为North

    clc

    clear

    close all

    Npoint = 101;

    x = linspace(0,10,Npoint);

    y1 = besselj(1,x);

    y2 = besselj(2,x);

    y3 = besselj(3,x);

    y4 = besselj(4,x);

    y5 = besselj(5,x);

    H = plot(x,y1,x,y2,x,y3,x,y4,x,y5);

    h1 = legend(H([1 3 5]),'First','Third','Fifthth','Location','North');

    set(h1,'Orientation','horizon')

    不显示方框:

    clc

    clear

    close all

    Npoint = 101;

    x = linspace(0,10,Npoint);

    y1 = besselj(1,x);

    y2 = besselj(2,x);

    y3 = besselj(3,x);

    y4 = besselj(4,x);

    y5 = besselj(5,x);

    H = plot(x,y1,x,y2,x,y3,x,y4,x,y5);

    h1 = legend(H([1 3 5]),'First','Third','Fifthth','Location','North');

    set(h1,'Orientation','horizon','Box','off')

    展开全文
  • 标签:高级用法1:指定legend显示的位置legend({‘str1‘,‘str2‘,‘strn‘},‘Location‘,‘SouthEast‘);比较鸡肋,画好图后树手动拖动就好了高级用法2:指定显示某几条曲线的legend:例如你有25条曲线,想显示...

    标签:

    高级用法1:指定legend显示的位置:

    legend({‘str1‘,‘str2‘,‘strn‘},‘Location‘,‘SouthEast‘);

    比较鸡肋,画好图后树手动拖动就好了

    高级用法2:指定显示某几条曲线的legend:

    例如你有25条曲线,想显示其中1,6,11,16,21的legend

    H = plot(data);

    legend(H([1 6 11 16 21],‘1,‘6‘,‘11’,‘16‘,‘21‘);

    高级用法3:legend横排

    hl = legend(H([1 6 11 16 21],‘1,‘6‘,‘11’,‘16‘,‘21‘);

    set(hl,‘Orientation‘,‘horizon‘)

    高级用法4:不显示方框:

    hl = legend(H([1 6 11 16 21],‘1,‘6‘,‘11’,‘16‘,‘21‘);

    set(hl,‘Box‘,‘off‘);

    查看这个的初衷是因为四条曲线的对比图,但是有些曲线差别太大,比如A在[1.8,1.82],B在[0.9,1.1],CD曲线在中间这样的话,因为A曲线的存在,中坐标最大值是1.82但是变化很不明显,所以该曲线在图的最上方,而且紧挨着图的上边界,因为图例在右上方,这样肯定会覆盖曲线,所以想着横排。

    20180110184443288249.png

    但是这种方法也不好做好的事拆开。

    Matlab提供的legend函数,给出的legend经常覆盖了某些曲线(尤其是用IEEE模板的时候,一般图片宽度不超过315px).

    a=linspace(0,2*pi,100);

    y1=100*sin(a);

    y2=50*cos(a);

    y3=tan(a);

    y4=log(a);

    y=[y1;y2;y3;y4];

    figure

    p=plot(a,y)

    legend(‘sin‘,‘cos‘,‘tan‘,‘log‘)

    如下图所示:

    d962b21e4b0a32faa1ecb7bbeeaaef4b.png

    Matlab画图实现两个或多个legend,不同排版

    这显然不是你想要的,你的reviewers也会肯定让你修改的!

    原因是Matlab的Legend函数,只能水平或者竖直排版!

    解决方法:把legend分成几个,相对独立,这样可以使用鼠标随意移动,确保不遮挡曲线。

    结果如下图所示:

    98c838962a9dbb541806f248808c0568.png

    位置可以随便写,图绘制好厚,手动拖动。

    a=linspace(0,2*pi,100);

    y1=100*sin(a);

    y2=50*cos(a);

    y3=tan(a);

    y4=log(a);

    y=[y1;y2;y3;y4];

    figure

    p=plot(a,y)

    legend(p(1:2),‘sin‘,‘cos‘);

    ah=axes(‘position‘,get(gca,‘position‘),...

    ‘visible‘,‘off‘);

    legend(ah,p(3:4),‘tan‘,‘log‘,‘location‘,‘west‘);

    标签:

    展开全文
  • CODE:Specifier Location in AxesNorthInside plot box near topSouthInside bottomEastInside rightWestInside leftNorthEastInside top right (default for 2-D plots)NorthWestInside top leftSouthEastIn...

    CODE:

    Specifier        Location in Axes

    North

    Inside plot box near top

    South

    Inside bottom

    East

    Inside right

    West

    Inside left

    NorthEast

    Inside top right (default for 2-D plots)

    NorthWest

    Inside top left

    SouthEast

    Inside bottom right

    SouthWest

    Inside bottom left

    NorthOutside

    Outside plot box near top

    SouthOutside

    Outside bottom

    EastOutside

    Outside right

    WestOutside

    Outside left

    NorthEastOutside

    Outside top right (default for 3-D plots)

    NorthWestOutside

    Outside top left

    SouthEastOutside

    Outside bottom right

    SouthWestOutside

    Outside bottom left

    Best

    Least conflict with data in plot

    BestOutside

    Least unused space outside plot

    展开全文
  • matlab 设置legend(比较全面)

    千次阅读 2020-05-29 23:50:19
    legend('sin(x)','cos(x)','Location','North');...Matlab中有许多位置可以选择: 'North' inside plot box near top 'South' inside bottom 'East' inside right 'West' inside left 'NorthEast' i
    legend('sin(x)','cos(x)','Location','North');
    
    Matlab中有许多位置可以选择:
            'North'          inside plot box near top
            'South'          inside bottom
            'East'           inside right
            'West'           inside left
            'NorthEast'       inside top right (default for 2-D plots)
            'NorthWest'       inside top left
            'SouthEast'       inside bottom right
            'SouthWest'       inside bottom left
            'NorthOutside'      outside plot box near top
            'SouthOutside'      outside bottom
            'EastOutside'       outside right
            'WestOutside'       outside left
            'NorthEastOutside'   outside top right (default for 3-D plots)
            'NorthWestOutside'   outside top left
            'SouthEastOutside'   outside bottom right
            'SouthWestOutside'   outside bottom left
            'Best'           least conflict with data in plot
            'BestOutside'      least unused space outside plot
    
    

    水平排列

    h1 = legend(H([1 3 5]),'First','Third','Fifthth','Location','North');
    set(h1,'Orientation','horizon')
    

    不要方框
    PS:不要方框,此时图例为透明的颜色,不会遮挡住数据线条

    h1 = legend(H([1 3 5]),'First','Third','Fifthth','Location','North');
    set(h1,'Orientation','horizon','Box','off')
    

    参考连接
    http://blog.sina.com.cn/s/blog_7db803c10102weyk.html

    legend详细介绍
    在这里插入图片描述
    PS:legend(vsb1)也可设置图例的:隐藏、表现、介于两者之间,没试出其效果

    如果想要在一张图上显示2个图例,需要加上下面这句话

    ah=axes('position',get(gca,'position'),'visible','off');
    

    呈现效果如下:
    在这里插入图片描述

    修改legend形状、大小等,添加标题等
    添加标题
    在这里插入图片描述

    添加颜色、大小等

    % Modify the legend appearance by setting Legend properties. 
     
    clear
    clc
    close all
     
    rdm = rand(4);
    plot(rdm)
     
    lgd = legend('Line 1','Line 2','Line 3','Line 4');
    lgd.FontSize = 12;
    lgd.TextColor = 'blue';
    lgd.NumColumns = 2;
    lgd.Location = 'southwest';
    leg.Orientation = 'vertical';
    title(lgd,'My Legend Title');
    

    在这里插入图片描述

    参考链接:https://ww2.mathworks.cn/help/matlab/ref/legend.html

    展开全文
  • Matlab设置Legend横排、分块

    万次阅读 2018-09-08 09:50:51
    1 2 3 4 5 6 7 ... 高级用法1:指定legend显示的位置legend({'str1','str2','strn'},'Location','SouthEast'); 比较鸡肋,画好图后树手动拖动就好了 高...
  • MATLAB legend设置

    2020-12-05 20:10:29
    x=0:0.2:12; plot(x,sin(x),'-',x,1.5*cos(x),':') legend('First','Second',-1); 设置数字的形式不行,这个应该是很久之前的用法 可以用这种方式确定位置 原始参考链接
  • 如何将legend设置在图片的任意位置 legy = legend('line1 ','line2 ','line3','fontsize',10,... 'position',[0.32 0.71 0.6 0.22]); legy.ItemTokenSize = [15,15]; legend('boxoff') 核心代码: position',...
  • Matlab图例设置

    2020-12-23 10:04:06
    1.图例的基本设置 legend('\alpha_1','\alpha_1','\alpha_1') 上图分别设置了三个图例 2.图例的位置 legend('\alpha_1','\alpha_1','\alpha_1',1) 0——图例尽量不与数据冲突,自动放置在最佳位置 1——放置在放置...
  • matlab 常用设置

    2015-05-28 17:23:15
    调整legend位置 clear all; clc; x = 0:pi/20:pi; y = sin(x); plot(x,y); legend('sinx',-1); % 位于图形框外面legend('sinx',0); % 最佳位置 legend('sinx',1); % 右上角 legend('sinx',2); % 左上角 legend('...
  • Python box = ax.get_position() ax.set_position([box.x0, box.y0, box.width, box.height...# loc图例位置; bbox_to_anchor上下偏移量; ncol一行的显示个数; Matlab h = legend('Model1', 'Model2', 'Model3', '
  • legend部分用法

    2017-03-01 15:26:16
    1.legend名字含有下划线问题 比如:act_color 使用方式:legend(‘act_color’),即需要在下划线前面加一个斜线就... legend显示位置设置 legend({‘act_color’,’act_style’},’Location’,’eastoutside’);
  • matlab小记(三)

    2018-04-06 19:53:00
    legend命令可以用来添加图例,其中在图例的放置过程中,容易与图形相重合,干扰我们观察图像,这时候legend中有个location参数,可以设置成Best,帮我们自动选择好位置, 使得图例的图标不会与图形造成干扰,示例:...
  • matlab科研绘图tip

    2021-03-16 20:36:13
    设置图例字体大小lgd=legend('期望输出', '实际输出'); lgd.FontSize = 12; legend('Location','best')% 图例的位置 legend('Orientation','horizontal') %平行排列图例 xlim([0,200]);ylim([0,..
  • matlab plot函数程序

    2018-07-22 16:39:55
    matlab中二维线画图函数 1. plot(x,y); %x y 为相应点集 2.plot(x,y1,x,y2); % 在一个窗口下绘制多条曲线之方法一 3.hold on %在一个窗口下绘制多条曲线之方法二 plot(x,y1); plot(x,y2); hold off 4.plot...
  • 3.3.1 设置视角位置 3.3.2 设置坐标轴 3.3.3 灯光效果设置 3.3.4 颜色的渲染 3.4 特殊的三维图形 3.4.1 三维离散序列图 3.4.2 三维填充多边形图 3.4.3 三维等高线 3.4.4 流水效果曲面图 3.4.5 圆柱体 3.4.6 球面图 ...
  • matlab、明天考试

    2018-12-24 22:08:00
    1.legend 新用法 设置位置 legend('标准点','随机点','Location','NorthWest'); 2.产生随机数 s3 = rand(1,5); --------------------------------------------------------------------------------------------...
  • 以下示例说明了如何创建图例并进行一些常规修改,例如更改位置设置字体大小和添加标题。我们还可以创建具有多列的图例,或为所绘制数据的子集创建图例。创建简单图例创建一个带有折线图和散点图的图形。为每个图表...
  • MATLAB绘图花样二

    2020-11-27 20:51:12
    %分割第一个数据,想突出那个数据就在该数据位置设置为1 pie(x,explode); 注释 x = [2,3,4]; pie(x,{'a','b','c'}); 分割+注释 x = [2,3,4]; pie(x,explode) %“;”加不加都可以 legend('a','b','c') pie3...
  • 以下示例说明了如何创建图例并进行一些常规修改,例如更改位置设置字体大小和添加标题。我们还可以创建具有多列的图例,或为所绘制数据的子集创建图例。创建简单图例创建一个带有折线图和散点图的图形。为每个图表...

空空如也

空空如也

1 2
收藏数 24
精华内容 9
关键字:

matlab设置legend位置

matlab 订阅