matlab - 如何在 MATLAB 中用两个子图更新一个图?
问题描述
我在 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(' ')
%....
解决方案
假设你的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);
重写需要一点点努力,但如果您将来想要添加的不仅仅是两条曲线,它肯定会有助于使您的代码可扩展。
推荐阅读
- snakemake - snakemake 参数函数 lambda
- php - PDOStatement 类的对象无法转换为字符串 - 首先选择,然后添加与表单对象组合的结果
- mysql - 为mysql加入3个表并出错
- java - 使用带有 lambda 的 Java 8 流来处理 for 循环,调用具有多个参数的方法
- javascript - firestore get方法完成后执行代码
- java - 如何使用协调器布局在android中将视图折叠到屏幕底部?
- peoplesoft - AddDropDownItem 人员代码
- vb.net - 在 vb.net 上自学
- javafx - JAVAFX - 带有可修改自定义 TimePicker 单元格的 Tableview 关闭太快
- c# - 如何在不多次传递的情况下从 autofac 父范围解析?