MATLAB: Is the PNG of the figure rotated 90 degrees

distortMATLABrotatestretchwarp

In MATLAB, my figure looks exactly how I want it to look in the figure window. However, when I save the figure as a PNG file, the resulting PNG inage is rotated 90 degrees. How can I make sure that the PNG looks exactly like the figure?
I use the following command to save my figure, "fig", as a PNG:
>> print(fig,'-dpng',pngName);

Best Answer

When the 'PaperOrientation' property of the figure is set to 'landscape' instead of 'portrait', the subsequent call to "print" saves the figure as a PNG image using this orientation specification. This could result in an image that is rotated 90 degrees from the orientation of the original figure.
This can be verified with the following command (while the figure "fig" is open):
>> get(fig,'PaperOrientation')
In order to resolve this issue, you can insert the following line before the call to "print":
>> set(fig,'PaperOrientation','portrait');
Refer to the following documentation page for more information about the Figure Properties for Printing and Saving: