altmany / export_fig

A MATLAB toolbox for exporting publication quality figures
BSD 3-Clause "New" or "Revised" License
1.27k stars 365 forks source link

Images are sometimes cut off #348

Closed AnselmDr closed 2 years ago

AnselmDr commented 2 years ago

Hello,

sometimes the exported figures are cut off somewhere in the picture horizontally.

example of cut off plot: cut off plot example of correct plot: correct plot

It doesnt produce an error message and the script keeps on being executed. The command is just in the simplest form:

export_fig(filename);

Executing the line again after the half image was exported fixes the file. The graphic is also nothing special, just a subplot with line plots. Are there any recomendations how to stop this problem?

altmany commented 2 years ago

Are you using the latest export_fig version?

AnselmDr commented 2 years ago

I downloaded the latest version and tried it again but sometimes it still happens.

AnselmDr commented 2 years ago

Hey, I did a little more testing and it only seems to happen when doing subplots. All images with a single plot are fine. Did you have any success with the issue?

AnselmDr commented 2 years ago

I found the cause: I used

set(groot, 'defaultFigureWindowState', 'maximized');

to maximize all figure windows created in my code. Unfortunately this causes the issue with the cut off Images. Another problem with setting a default value is, that it doesnt get cleared by clear all and the like. use

reset(groot)

at the beginning of the code if you want to be sure to have no problematic default settings making trouble.

The other options, minimized and fullscreen also mess up the images.

Instead use either

set(groot,'defaultfigureposition',[0 0 1920 1080])

or set the window size for each figure with for example


f1 = figure(1);
f1.Position = [0 0 1920 1080];

nice thing is, it works even when you disable that the figure windows are displayed

set(0, 'DefaultFigureVisible', 'off')

Edit:

Setting the figure at the size of the screen or larger causes issues. likely because position [0 0] is above the taskbar so a figure as large as the screen actually portrudes it at the top. so its better to set it at a smaller value. @altmany you might wanna look into this although I found a workaround for my issue.

altmany commented 2 years ago

I cannot reproduce the issue, even with maximized figures. I suspect that the underlying cause is that you're trying to export the figure before it is fully rendered by Matlab - graphics rendering happens in the background, so you might be calling export_fig before it has in fact completed. One workaround is to add a call to drawnow and possibly also a short pause (e.g. pause(0.5)) after you create the figure and before you call export_fig.

AnselmDr commented 2 years ago

Hm okay, well if someone else has this problem they maybe find my solution here. the workaround with pause and drawnow also didnt work for me.