Current figure window resizes when calling "print" [recent change in functionality]?

I'm using 2018b on MS Windows 10 and have recently noticed that calling either of
print(gcf)
print(gcf,'-dpng','filename.png')
first resizes the gcf window before printing. I believe this has something to do with MS Windows and printers (even software printers?), as I think the behavior changed after a MS Windows auto update (and I am fairly confident that this was not the default behavior at other times while using 2018b).
Is this a known issue? Can I make it stop? I use print regularly for figure export to image files, and resizing the gcf window changes aspect ratio, font size, etc.

6 件のコメント

As a clarifying note, I do NOT mean that the exported figure is some unexpected size (although that is true as well), I mean that the gcf window ITSELF changes from whatever size/position I have it set at to now be at (my setup's default position)
a = gcf;
a.Position
404 246 560 420
Jan
Jan 2019 年 1 月 11 日
H = figure('Position', [100, 100, 200, 160]);
drawnow;
H.Position
print(H)
H.Position
Does this mean, that you get different outputs for this code? And the output does have an unexpected size? Which size? Does your figure has a ResizeFcn?
Interestingly, no -- that one worked (the figure stayed with position [100,100,200,160] throughout).
This led me down an interesting path about the maximize button in Windows. This is the behavior I can now confidently report:
H = figure;
H.Position
ans =
404 246 560 420
% MANUALLY CLICK THE WINDOWS 'MAXIMIZE' BUTTON IN THE UPPER RIGHT CORNER OF THE WINDOW
H.Position
ans =
1 -281 1920 973
print(H); % Results are the same if calling print(H,'-dpng','tmp.png')
H.Position
ans =
404 246 560 420
% Window has reverted to earlier size AND has become the active/current focus window
% Now try resizing manually:
set(H,'Position',[1 -281 1920 973]);
print(H);
H.Position
ans =
1 -281 1920 973
% H has NOT become the active window, but rather matlab console or editor retains current focus
So it seems like this maybe only happens if I hit the Mxaimize/Restore Down button. A fascinating piece of this is the following:
H = figure;
H.Position
ans =
404 246 560 420
% MANUALLY CLICK THE WINDOWS 'MAXIMIZE' BUTTON IN THE UPPER RIGHT CORNER OF THE WINDOW
H.Position
ans =
1 -281 1920 973
% Now manually set the gcf position:
set(H,'Position',[1 -281 1920 973]); % Manually set the position to be the same is it is currently
print(H);
H.Position
ans =
404 246 560 420
So I think that any time I have touched the maximize button, the next call to print will make the figure active, resize it, and then print.
As for ResizeFcn, I haven't come across these before, so am looking into what it means (presumably no is the answer?).
Dan Gianotti
Dan Gianotti 2019 年 1 月 11 日
編集済み: Dan Gianotti 2019 年 1 月 11 日
As I dig around, another noticeable point is that the resizing happens sometime in the call to print. If I run
print(H); H.Position
on one line in the console (or by selecting them both in the editor and pressing F9, or using Ctrl+Enter as a code block, etc.) then the reported size is [1 -281 1920 973], but if I wait a second in between the commands, then the window resizing will have already occurred and H.Position gives [404 246 560 420], which makes me think this is something about MS Windows printing stuff taking control of the figure window away from Matlab.
Long story short, I can work around this no problem by never again touching the maximize button for figures. But it seems strange/not optimal.
EDIT:
In response to your question about the output sizes, if I maximize a figure, then call print, the output file is of a size and aspect ratio corresponding to the maximized figure. Then, within the output file, the printed image will be the size of the (newly-resized) figure. So for a png, my image will now be ~ 80% whitespace with a little figure printed somewhere inside. This does not happen if I do not touch the maximize button. Maybe Matlab tells the printer driver what size page first, then Windows makes the figure active and resizes the figure, then Matlab passes along the figure data? (I, perhaps obviously, have no idea how printer drivers work...)
Walter Roberson
Walter Roberson 2019 年 1 月 11 日
MATLAB resizes the figure and changes its background during print in order to satisfy PaperPosition and Hardcopy inverse requirements , and then changes back. This is often visible. There are race conditions if you try to interact with the figure during that time.
Jan
Jan 2019 年 2 月 27 日
編集済み: Jan 2019 年 2 月 27 日
[MOVED from section for answers] Steve Grobler wrote:
Hi Dan,
I am finding the same issue. It's extremely annoying! (Windows 7 Professional)
Thank you for investigating and isolating the cause.
I've noticed that if I manually re-size the figure instead of (or after) using the maximise button, then the problem also does not occur.

サインインしてコメントする。

回答 (1 件)

Christopher Beckett
Christopher Beckett 2019 年 12 月 19 日
Hi all,
I found this same issue as well and related it back to the print command. Instead of using print, I used the saveas function:
set(gcf,'PaperUnits','inches');
set(gcf,'PaperSize', [16 8]);
set(gcf,'PaperPosition',[-1 0 18 8]);
set(gcf,'PaperPositionMode','Manual');
saveas(gcf,'MyFig.pdf')
which has worked so far, with the same result as when using "print" with Windows 8, i.e. the saved figure is no longer affected by window resizing.

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2018b

質問済み:

2019 年 1 月 10 日

回答済み:

2019 年 12 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by