Q:

Why does Matlab add this line to plot when saving?

I've been trying to plot some inequalities in Matlab.
When it shows in Matlab figure, it looks right:

But when I save the figure, I get this annoying yellow line (both when saved manually and when saved in code):

The code which produces the plot is:
function [  ] = plotInequalities( ~ )

pRange = linspace(1/2,1,1000);
cRange = linspace(0,1,1000);
[P, C] = meshgrid(pRange,cRange);
ineq1 = P >= 2/3;           
ineq2 = C.*P.*(3-4.*P)./(2.*P+C.*(2-4.*P)) >= 1-P; 
ineq3 = C <= 3.*P.*(1-P)./(2.*(-6.*P.^2+6.*P-1));
rest = ~ineq1 & ~ineq2 & ~ineq3;                      
pl = figure
hold on
c = 2:5; 
contourf(pRange, cRange, c(2) * ineq2, [c(2), c(2)], 'c')  
contourf(pRange, cRange, c(3) * ineq3, [c(3), c(3)], 'y')  
contourf(pRange, cRange, c(4) * rest, [c(4), c(4)], 'r') 
contourf(pRange, cRange, c(1) * ineq1, [c(1), c(1)], 'b')  
legend('\{A,AB\}', '\{A,B\}', '\{A,AB, B\}', '\{A\}')
xlabel('P')
ylabel('C')
saveas(pl, 'out.png','png');
end

I'm using Matlab R2014a on Windows 8.

Any idea as to why this happens?

A:

This is because there is an overlap between your domain ineq1 and ineq3.
If you set the renderer of the figure to anything else than painter (e.g. opengl or zbuffer) you will see the line which represent the border of your domain ineq3 (which should be hidden under ineq1)
When the figure is printed with the Matlab engine (for png,jpg,tiff etc ...), I couldn't force the print command to use the painter renderer. If you use one of the format rendered with the gostscript engine (pdf, bmp,pcx,pcm,...) then the proper output is produced.
If you want to stick to png output, the simple way around is to ensure there is no overlap between your domains before you send them to the contourf function. So in your case just add the line:
ineq3(ineq3==ineq1) = false ;

just before you call the different contourf, and the ouput will be OK in the figure and in the image saved (because there will be no ghost line to confuse the rendering engine).
Of course with this method, the order of overlap is important. This solution assume you want to see the full domain ineq1 and it has priority over the domain ineq3. If you want a different priority you have to change which domain override the other.
PS: and if you want the border of all domains to be visible, consider using patches and transparency so the overlaps will be more obvious.

