MATLAB Answers

Saving plot in coloful png format

4 views (last 30 days)
Marat Zhe
Marat Zhe on 16 Oct 2015
Edited: 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...
Marat Zhe
Marat Zhe on 16 Oct 2015
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.

Accepted Answer

Walter Roberson
Walter Roberson on 16 Oct 2015
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!