MATLAB Answers

0

Saving plot in coloful png format

Asked by Marat Zhe on 16 Oct 2015
Latest activity Edited by Marat Zhe on 16 Oct 2015
__Hi dear MathWorks staff and other matlab users. I made calculation using MATLAB and got figure with contourf plot. In figure i see filled colorful plot. But when i try to save (file-save as) it in png format, i get plot in black and white. Can you explain me, what is my error? I attached matlab figure ive got. Thanks in advance.
__P.S. Thank you Stephen Cobeldick. You are right - i confused two companies. Now i corrected my post...

  5 Comments

I made small experiment. I commented line 92 of m-file " Question_eng.m", i.e.
%hold on;
After this, i run program and get figure. This figure i can save in colorful png with no problem...
However you would not get the white background the same way.
I am new here and i haven't noticed valuable answers down this page.
I saw only comments.....
Thanks to all participants, who discussed question.

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 16 Oct 2015
 Accepted Answer

I was testing in R2014a, which is important because graphics changed in R2014b in ways that matter to this situation.
In R2014a (and earlier) when you select save as for PNG, the renderer gets switched to OpenGL from Painters. There is then a conflict in the layering between the rectangle with 'facecolor', 'w', and the contour plot: both of them are in the plane z = 0, so the renderer has to decide which has priority. In Painters the rule is "whichever one was drawn last", but in OpenGL the rules are more complicated. The OpenGL rules tend to prioritize lines over surfaces, which is why the lines show up. But with coplanar surfaces, I do not recall what the rule is.
For R2014a or earlier, you are going to have to push the rectangle into negative Z or pull the contour plot into positive Z. You can use a hgtransform to parent the object, with makehgtform with a Z translation as the Matrix. Or you could replace the rectangle with a patch that had a negative Z. (The purpose of the rectangle() being essentially to provide the white background and the circular edge drawing.)
For R2014b or later, you have another option: you can also use the new SortMethod property, which is discussed in Mike's blog . Watch out for the limitation discussed at the bottom about "some graphics cards" and about PDF.
The more robust method is to ensure that the contours are "above" the rectangle, even if only a tiny bit.

  0 Comments

Sign in to comment.