Why are the top and bottom parts of my MATLAB figure cropped when I use SAVEAS to save a figure to a PNG-file?

29 views (last 30 days)
Why are the top and bottom parts of my MATLAB figure cropped when I use SAVEAS to save a figure to a PNG-file?
When I try to save my figure to a PNG-file using SAVEAS, the top and bottom parts of the image are cutoff. However, when I use SAVEAS to save my figure to a BMP-file, the figure appears just fine. If I use PRINT instead of SAVEAS, the cropping occurs for either file format. For example:
figure;
set(gcf,'position',[0 0 1000 800]);
axes('fontsize',28);
title('Title');
xlabel('X Axis');
saveas(gcf,'tmp','png');
saveas(gcf,'tmp','bmp');

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Feb 2011
This is a bug in MATLAB 6.5 (R13) in the way that SAVEAS handles PNG-files. Our development staff is investigating this issue.
Currently, to work around this issue, try the following:
figure;
set(gcf,'position',[0 100 1000 800]);
axes('fontsize',28);
title('Title');
xlabel('X Axis');
f=getframe(gcf);
[X, map] = frame2im(f);
imwrite(X,'tmp.bmp');
imwrite(X,'tmp.png');
You will notice that the "Position" property has been changed to move the figure window above the Windows taskbar which is typically at the bottom of the screen. This is currently necessary to avoid including the taskbar in your saved image. Our development staff has been notified and is currently investigating this issue as well.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!