• matlab⾼级绘图时间距离图像


    这限制了可能在legend上⼯作以实现⽬标的可能性。
    可能的解决⽅案是按照以下步骤创建⾃⼰的基于轴的图例:
    使⽤以下语法[lgd,icons,plots,txt] = legend(___)创建调⽤legend函数的图例(注意,不建议使⽤此语法,我们将在后续步骤中删除图例,
    因此不会出现问题)
    获取传奇的位置
    标识图例中的项⽬数
    对于图表中的每⼀⾏,图例中有三个项⽬(line,marker和text)
    如果图表中有六⾏,则图例句柄将按以下顺序包含18对象:
    6个处理text
    对于6⾏中的每⼀⾏
    该⾏的句柄
    标记的1个句柄
    获取图例中项⽬的数据:
    ⾏数据:XData,YData,Color,'LineStyle`
    ⽂字资料:string,position
    删除原始图例
    将axes添加到图中,其位置和⼤⼩等于原始图例
    在此轴上绘制代表图例的线条(您已获得前⾯步骤的数据)
    缩⼩线条,只减少减少XData第⼆元素的值
    将图例⽂本对应添加到该⾏(使⽤text函数。由于在上⼀步中您已经恢复了要在左侧移动⽂本的⾏的长度
    减⼩axes的⼤⼩:
    您可以使⽤text项⽬的Extent属性来识别较长的项⽬的长度
    然后添加相应⾏的长度
    使⽤上述步骤中计算的值更新axes位置(其width)
    这是⼀种可能的实现(基于您的代码):

    x = randn(6,20);
    figure(2)
    hax = gca;
    plot(x(1,:),'--k','linewidth',1.5);
    hold on;
    plot(x(2,:),'b','linewidth',1.5);% hold on;
    plot(x(3,:),'g','linewidth',1.5);
    % hold on;
    plot(x(4,:),'r','linewidth',1.5);
    % hold on;
    plot(x(5,:),'c','linewidth',1.5);
    % hold on;
    plot(x(6,:),':r','linewidth',1.5);
    ylabel('states','fontsize',14); xlabel('time(s)','fontsize',10);
    %legend('True','SCKS(h1)','SCKS(h2)','SCKS(h3)','SCKS(h4)','DEM',14);
    %
    % New call "legend"
    %
    [leg_h,leg_item_h,~,~]=legend('True','SCKS(h1)','SCKS(h2)','SCKS(h3)','SCKS(h4)','DEM',14);
    %
    % legendshrink(0.8,[]);
    %Fig_legend = legend('Taylor','Euler','LLscheme','LLscheme1');
    %set(Fig_legend,'FontSize',7)
    grid(hax,'on')
    % axis(hax,'tight')
    set(hax,'box','on','Layer','top');
    set(hax,'tickdir','out')
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % GENERATION OF THE LEGEND %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Define a scale factor fot the lines
    line_scale_factor=1.4;
    % Define a scale factor fot the lines
    text_scale_factor=1.35;
    % Get the "Position" of the legend
    orig_leg_pos=get(leg_h,'position')
    % Get the number on objects in the legend
    n_obj=length(leg_item_h);
    % Extract the "Line" objectline_obj=leg_item_h(n_obj/3+1:2:n_obj);
    % Get the "LineStyle" of each "Line" in the legend
    l_style=get(line_obj,'LineStyle')
    % Get the "Color" of each "Line" in the legend
    l_col=cell2mat(get(line_obj,'color'))
    % Get the "XData" and "YData" of the "Lines" in the legend
    leg_x_data=cell2mat(get(line_obj,'xdata'))
    leg_y_data=cell2mat(get(line_obj,'ydata'))
    % Get the handle of the "Text" of the items in the legend
    leg_t=leg_item_h(1:n_obj/3)
    % Get the "Text" of the items in the legend
    str=get(leg_t,'string')
    % Get the "Position" of each "Text" item in the legend
    tx=cell2mat(get(leg_t,'position'))
    % Delete the original legend
    delete(leg_h)
    % Create an axes with the same position and size of the original legend
    ax=axes('position',orig_leg_pos,'xlim',[0 1],'ylim',[0 1], ...
    'xtick',[],'ytick',[],'box','on')
    hold on
    % Add the legend items to the axes
    for i=1:n_obj/3
    % Add the lines with the original settings (color, style, ...)
    plot([leg_x_data(i,1) leg_x_data(i,2)/line_scale_factor],leg_y_data(i,:),'color',l_col(i,:), ...
    'linestyle',l_style{i}, ...
    'linewidth',1.4)
    % Add the text
    th(i,:)=text(leg_x_data(i,2)/text_scale_factor,tx(i,2),0,str{i},'fontsize',9, ...
    'unit','normalized')
    end
    % Get the maximun extent of the lagend "Text"
    tx_max_ext=max(reshape([th(:).Extent],4,6)');
    % Evaluate the axis scaling factor
    tx_r_1=tx_max_ext(3)+leg_x_data(i,2)/line_scale_factor% Get the axes position
    axp=ax.Position
    % Resize the axes width
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74

    在这里插入图片描述

  • 相关阅读:
    [Rust学习:三] 循环和切片
    MySQL的介绍
    oracle19c集群日志路径与11g不同
    公司大数据智能管理平台密码不正确 Hue平台进不去
    【阅读笔记】Java游戏服务器架构实战(待更新)
    git使用
    Python|OpenCV-色彩空间之RGB轨迹调试板(5)
    深夜学习:有关Inner、Outer等相关词汇的理解
    【HttpRunnerManager】搭建接口自动化测试平台实战
    activemq的安全机制、Connection使用方法、Session的使用方法、签收模式、使用事务
  • 原文地址:https://blog.csdn.net/m0_38127487/article/details/128196188