set(gcf,'Position') not working?
98 ビュー (過去 30 日間)
古いコメントを表示
Matlab does not seem to be letting me set my figure position in some cases, for no apparent reason. Code:
scrsz = get(0,'ScreenSize');
figure('Visible','off','color',[1,1,1]); %background to white
set(gcf,'MenuBar','none');
set(gcf,'NumberTitle','off');
set(gcf,'Position',scrsz + [0 0 0 50]);
axis([-scrsz(3),scrsz(3),-scrsz(4),scrsz(4)+200]); %Changes the data pixel size of the workspace.
set(gca, 'Position', get(gca, 'OuterPosition')); %removes annoying outer white boundary box
set(gca,'xcolor',get(gcf,'color')); %these next four lines make the actual axis lines and their tick marks be white and thus invisible.
set(gca,'ycolor',get(gcf,'color'));
set(gca,'ytick',[]);
set(gca,'xtick',[]);
set(gcf,'Visible','on');
In line #5 there, I have the "+ [0 0 0 50]" which should nudge the entire figure to be 50 pixels taller than before (thus getting the menu bar off the screen so I have a pure white display).
But it does nothing. Even when I isolate just that by typing out get(gcf,'Position') set(gcf,'Position',[1 1 1920 1107]) get(gcf,'Position')
It will display [1 1 1920 1057] and then again [1 1 1920 1057] So it is just straight up ignoring my instructions.
If I add +[0 50 0 0] instead, though, it is perfectly happy to push the menu bar off the screen (though it leaves a non-figure area below). But it refuses to do it with stretching?
I don't get it.
0 件のコメント
回答 (7 件)
Andre
2015 年 4 月 3 日
I had the same problem. The figure flashed at the position I wanted it then moved back to the original place. It stopped doing that when I set Resize to off. Just set:
set(gcf,'Resize','off')
Before redefining position. Hopefully it works for you too.
0 件のコメント
Michael Thursby
2022 年 6 月 2 日
I just updated to 2022a and now my code does the same thing. I think we need matlab staff to weigh in on this real problem. I depend on being able to position my windows as needed not as matlab likes. I organize eight windows on a second screen for visibility and now it won’t do it !!!
4 件のコメント
Thomas
2023 年 3 月 22 日
編集済み: Thomas
2023 年 3 月 22 日
I'm hitting the same problem with 2022a. I just want to make a lot graphs that are the same size so I can print them to identically sized .png files. The figures are not anywhere near an edge, but MATLAB tweaks the height and width several pixels anyway. My workaround is to issue all the plotting commands, then drawnow, then set the figure position.
MathWorks, please fix this!
Massimo Ciacci
2023 年 3 月 25 日
The best approach to date is to restart Matlab and give up using anything else than get(0,'MonitorPositions'). This is because when you apply set(gcf,'Position') it's what Matlab thinks the screen size is that places the figure.
Even if you manage using undocumented code to get the true screen size, you will be fiddling for hours to no avail, unless there is some undocumented Matlab to set the position.
I actually see this happening to all my colleagues as well, since several years, as soon as they attach a second monitor, I tell them they need to restart Matlab. No other solution to this unfortunatley.
Jan
2013 年 6 月 3 日
Yes, Matlab sets the figure position stubbornly when it exceeds the visible area of the primary screen at least sind version 5.3. Sometimes setting the position twice helps (!).
Because I needed full-screen windows, I've created a Mex function for resizing the window without calling Matlab's internal resize function, see FEX: WindowAPI. Even from inside the Mex, the Windows API function SetWindowPos() requires the SWP_NOSENDCHANGING flag to avoid Matlab's smart independent decision to move the figure where it wants the user to want it.
A similar effect happens for the minimal horizontal size of a figure.
Please send an enhancement request to TMW and ask them not to set the figure position magically, because this has no benefit.
Dennis Dunn
2017 年 11 月 16 日
編集済み: Dennis Dunn
2017 年 11 月 16 日
I'm having the same problem using Matlab R2017a on Ubuntu 17.04, where calling for example:
figure();
set(gcf, 'Position', [0 0 800 400])
get(gcf, 'Position')
returns [31 11 800 400] or something similar. I tried using
set(gcf,'Resize','off')
but it's still auto-resizing afterward, but only sometimes randomly. I think it's because the new figure is being placed slightly off-screen, where each successive call places new figures slightly lower than the predecessor (I was generating animation frames). I solved the problem by reusing my figures to avoid creating new figures whenever possible. This solved it. Note that this problem only happens on Ubuntu, not on Windows or MacOS.
0 件のコメント
Sean de Wolski
2012 年 3 月 30 日
Sounds like the axes' property DataAspectRatio is superseding the set of your position.
0 件のコメント
Myhan PARK
2013 年 6 月 3 日
I had the same problem (version R2013a). Dual monitor size was returned correctly, but resizing my figures did not work correctly. It seemed that this was caused because the second monitor was connected while Matlab was already open. Restarting Matlab solved the problem ...
0 件のコメント
Steven Lord
2023 年 3 月 25 日
This was not an option when the original question was asked, but if you want the figure to cover the entire screen change its WindowState property to 'fullscreen' rather than trying to manipulate the Position property. You may also need or want to set the MenuBar and/or ToolBar properties to 'none' as well.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!