Why is the PNG of my figure rotated 90 degrees?

1 view (last 30 days)
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);

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Nov 2025 at 0:00
Edited: MathWorks Support Team on 10 Nov 2025 at 11:55
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');
For the latest release documentation on figure properties, please refer to:

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!