如何在线性图形循环中获得动态图例? [英] How to Get Dynamic Legend on Linear Graph in Loop?

查看:299
本文介绍了如何在线性图形循环中获得动态图例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

差异条件:如何在每次迭代结束时清除动态图例;如何在每次迭代结束时删除拟合的线性线。



我正在尝试扩展此线程的答案



Matlab:2016a

操作系统:Debian 8.5 6位

Linux内核:4.6的backports

硬件:华硕Zenbook UX303UA

解决方案

删除此行 legend(' - DynamicLegend'); 并将它写在 drawow 行之前,并写入 / code>之后。所以以下将是你循环结束的行。

  legend(' -  DynamicLegend'); 
drawnow;
暂停
index = index + 1;


Diff conditions: how to clear dynamic legends at the end of each iteration; how to remove fitted linear lines at the end of each iteration.

I am trying to extend this answer of the thread Dynamic Legend (Updates in every recursion) to iterate legend on one graph. Proposal to cover dynamic legend on one linear graph

close all; clear all; 

% Test data
aSize=zeros(2,777);
aSize=[[0, 0]' randi(3,2,777)]; % STDEV about 3

x=0:1:180; 

hFig=figure; 

index=1;
while (index<=7); 

    % origo left alone
    aSize(:, index+1) = aSize(:, index+1) + index; % to have linearly increasing trend

    sz=40; 
    legend('-DynamicLegend');
    h = scatter(aSize(1,1:index+1)', aSize(2,1:index+1)', sz, ...
          'MarkerEdgeColor',[0 .5 .5],...
          'MarkerFaceColor',[0 .7 .7],...
          'LineWidth',1.5, ...
          'DisplayName', sprintf('Data'));
    xlabel('width'); ylabel('height');
    hold on; 

    % Optimum
    x=0:1:max( aSize(1, 1:index+1) ); 
    y = x; % assume uniform
    grid on; 
    h1=plot(x,y, 'black', ...
        'DisplayName', sprintf('Optimum'));

    % Fit with R2 linear
    x=aSize(1,1:index+1); 
    b1 = aSize(1,1:index+1)' \ aSize(2,1:index+1)'; 
    yCalc1 = b1 * aSize(1,1:index+1);
    Rsq1 = 1 - sum((y(1:index+1) - yCalc1).^2)/sum((y(1:index+1) - mean(y(1:index+1))).^2)

    % origo needed
    x = [0 x]; 
    yCalc1 = [0 yCalc1]; 
    h2=plot(x(1:index+2)', yCalc1(1:index+2)', '--p', ...
        'DisplayName', sprintf('Fit R2 = %d', Rsq1)); 

    drawnow; 

    index=index+1;

end;

Output unsuccessful where legends are just appended

Matlab: 2016a
OS: Debian 8.5 6 bit
Linux kernel: 4.6 of backports
Hardware: Asus Zenbook UX303UA

解决方案

Remove this line legend('-DynamicLegend'); and write it just before the drawnow line and write hold off after that line. So the following will be the lines at the end of your loop.

legend('-DynamicLegend');
drawnow; 
hold off
index=index+1;

这篇关于如何在线性图形循环中获得动态图例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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