recipes : Plotting : Plot Manipulation : Positioning figures on the screen


How do I define where a figure will appear on-screen?


You obtain the size of the screen in pixels and then position the figure with respect to this.

ss = get(0,'screensize'); %The screen size
width = ss(3);
height = ss(4);

H = figure; %Make a new figure and store the handle
%Let's say we want it to take up 300 by 600 region of the screen:
vert = 300; %300 vertical pixels
horz = 600; %600 horizontal pixels

%This will place the figure in the top-right corner
set(H,'Position',[width-horz, height-vert, horz, vert]);

%Plot something in it:

%You can now move it to the middle of the screen if you like:
set(H,'Position',[(width/2)-horz/2, (height/2)-vert/2, horz, vert]);

In the above example, the 0 in get(0,'screensize') and the H in H=figure are both handles. Handles are just numbers that MATLAB uses to access a resource such as a window, plot element, or hardware device. Typing get(H) will reveal what other properties are available for figure windows. The set command allows you to modify these.