如何在MATLAB中用两个子图更新图?

问题描述 投票:0回答:1

我在MATLAB中有一个函数,它绘制了两条曲线并运行了两次。

在第一次绘制主曲线时,您可以看到红色(第一个绘图),然后转动“保持”并再次使用绿色(第二个形状)执行我的功能。

问题是左侧子图不起作用并删除第一条曲线(红色曲线),但第二条曲线工作正常(最后一个曲线)。

我的主要脚本是:

% some code to processing
...
roc('r.-',data); %this function plots my curves

并在第二次运行

% some code to processing
...
plot on
roc('g.-',data);

我的roc功能包含:

%some code
...

  subplot(1,2,1)
    hold on
    HCO1=plot(xroc(J),yroc(J),'bo');
    hold off
    legend([HR1,HRC1,HCO1],'ROC curve','Random classifier','Cut-off 
point','Location','NorthOutside')
    subplot(1,2,2)
    hold on
    HCO2=plot(1-xroc(J),yroc(J),'bo');
    hold off
    legend([HR2,HRC2,HCO2],'ROC curve','Random classifier','Cut-off 
point','Location','NorthOutside')
    disp(' ')
%....

enter image description here

matlab plot matlab-figure subplot
1个回答
1
投票

假设你的roc函数计算xroc和yroc我建议你重写你的代码来模块化它

function [xroc,yroc] = roc(data)
%your algorithm or training code
%xroc=...
%yroc=...
end

这样你的主脚本可以编辑成这样的东西

%first run
[xroc1,yroc1] = roc(data);
%...some further processing with data variable
[xroc2,yroc2] = roc(data);
%plots
ax1 = subplot(1,2,1,'nextplot','add');          %create left axes
ax2 = subplot(1,2,2,'nextplot','add');          %create right axes (mirrored roc)
%now you can go ahead and make your plots
%first the not mirrored plots
plot(xroc1,yroc1,'r','parent',ax1);
plot(xroc2,yroc2,'g','parent',ax1);
%and then the mirrored plots
plot(1-xroc1,yroc1,'r','parent',ax2);
plot(1-xroc2,yroc2,'g','parent',ax2);

重写是一点点努力,但如果你想在未来添加两条以上的曲线,它肯定会有助于使你的代码可扩展。

© www.soinside.com 2019 - 2024. All rights reserved.