0

I have this code:

fig = figure('visible','on');
plot(0:0.1:2*pi,sin(0:0.1:2*pi))
grid on
grid minor
set(gca,'FontSize',20,'xtick',0:0.5:2*pi)
saveas(fig,'plot','png')

When the plot is saved, it is not maximized and hence the tick numbers cram into each other. I used the solution from this question, but it did not work:

fig = figure('visible','on');
plot(0:0.1:2*pi,sin(0:0.1:2*pi))
grid on
grid minor
set(gca,'FontSize',20,'xtick',0:0.5:2*pi)
set(gcf,'units','normalized','outerposition',[0 0 1 1])
saveas(fig,'plot','png')

How can I save the figure fully maximized?

The good saved plot when I manually saved it: enter image description here

The bad one which is saved programmatically: enter image description here

Community
  • 1
  • 1
MOON
  • 2,516
  • 4
  • 31
  • 49
  • My recomendation is always: use `export_fig` from the file exchange – Ander Biguri Mar 03 '16 at 10:08
  • you may take a look to my recently added answer [there](http://stackoverflow.com/questions/15286458/automatically-maximize-figure-in-matlab) – serial Mar 14 '16 at 07:57

1 Answers1

2

There are plenty of solutions given in the quoted post. The following solution works for me:

fig = figure('visible','on');
plot(0:0.1:2*pi,sin(0:0.1:2*pi))
grid on
grid minor
set(gca,'FontSize',20,'xtick',0:0.5:2*pi)
pause(0.1)
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
pause(0.1)
set(fig, 'PaperPositionMode', 'auto');
saveas(fig,'plot','png')

Best regards

Sebastian
  • 124
  • 1
  • 9
  • It works. However, it gives this warning-> `Warning: figure JavaFrame property will be obsoleted in a future release` – MOON Mar 03 '16 at 11:39