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

2
  • My recomendation is always: use export_fig from the file exchange Commented Mar 3, 2016 at 10:08
  • you may take a look to my recently added answer there Commented Mar 14, 2016 at 7:57

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

It works. However, it gives this warning-> Warning: figure JavaFrame property will be obsoleted in a future release

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.