0
votes

I have a function in MATLAB and it plots two curves and I run it two times.

On the first time plot main curve as you can see in the red color (first plot) and after that turn the "hold on" and execute my function again with the green color (second shape).

The problem is that the left subplot does not work and delete the first curve (red curve) but the second one works fine (last plot).

My main script is:

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

and on the second run

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

and my roc function contains:

%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

1
Your code plots blue lines. Where is the code that changes the line color? And where is the code that plots the two diagonal lines? It’s possible that stuff you’re not showing is deleting a line. This is why we always ask for a minimal reproducible example here. If you put in the effort to make that, I’m sure you’ll find your own bug...Cris Luengo

1 Answers

1
votes

Assuming your roc function calculates xroc and yroc I suggest you rewrite your code to modularize it

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

this way your main script could be edited to something like this

%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);

it is a little effort to rewrite but it surely will help to make your code scaleable to if you want to add more than just two curves in future.