Why does Matlab add this line to the graph on save?

I am trying to plot some inequalities in Matlab.

When it appears in a Matlab figure it looks correct:

enter image description here

But when I save the digit, I get this annoying yellow line (both when saving manually and when saving code): enter image description here


The code that creates the graph:

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 am using Matlab R2014a on Windows 8.


Any idea as to why this is happening?

+3


source to share


1 answer


This is because there is overlap between your domain ineq1

and ineq3

.

If you set the shape rendering to anything other than painter

(like opengl

or zbuffer

), you will see a line that represents your domain border ineq3

(which should be hidden in ineq1

)

When the image is printed using Matlab mechanism (for png

, jpg

, tiff

etc.), I could not get the team print

to use the renderer painter

. If you are using one of the formats created with the engine gostscript ( pdf

, bmp

, pcx

, pcm

, ...), then create a correct conclusion.

If you want to stick with the inference png

, an easy way is to make sure there are no matches between your domains before sending them to the function contourf

. So in your case, just add the line:



ineq3(ineq3==ineq1) = false ;

      

before you call another contourf

and the output will be done on the figure and in the saved image (because there won't be a ghost line to confuse the rendering engine).

Of course, overlapping consistency is important with this method. This solution assumes that you want to see the full domain ineq1

and that it takes precedence over the domain ineq3

. If you need a different priority, you must change which domain overrides the other.

PS: and if you want the border of all domains to be visible, consider using patches and transparency to make the overlaps more obvious.

+3


source







All Articles