Code covered by the BSD License  

Highlights from
Precise Figure Placing

image thumbnail
from Precise Figure Placing by Markus Buehren
This contribution provides functions for precisely placing a figure to a given screen location.

placefigure

PRECISE FIGURE PLACING

Preamble

I have put a lot of effort into this contribution to Matlab Central. As I used the code successfully for myself for quite some time, I am sure that it can be rather valuable for the one or the other. If you find any errors or bugs, if you have problems in using the function or if you find the documentation insufficiently detailed:

Please contact me and give me the chance to help you before giving a bad rating on Matlab Central!

Contact details at the bottom of this page.

Introduction

This contribution provides functions for precisely placing a figure to a given screen location, like the upper left corner, the top half of the screen or the full screen. The figure is placed precisely adjacent to the screen borders and will not overlap the task bar at the screen bottom. In order to achieve this, the left and right borders of a figure as well as the height of the figure head, the menu bar etc. are obtained by analyzing a screen shot of a test figure.

Installation

Unpack all files into a single directory. Add path to the directory (using addpath) to be able to call the functions from any other directory.

Main functions contained in this package

placefigure.m

Function to place an existing figure to a given screen location. Please read the help comment for details.

Example 1:

fh = figure;
placefigure(fh, 'top left');

Example 2:

fh1 = figure;
fh2 = figure;
fh3 = figure;
fh4 = figure;
placefigure(fh1, [2 2 1 1]);
placefigure(fh2, [2 2 1 2]);
placefigure(fh3, [2 2 2 1]);
placefigure(fh4, [2 2 2 2]);

placefiguredemo.m

Starts a demonstration of the capabilities of this package.

computefiguresizeinfo.m

Retrieve figure size information like the left and right border widths, the height of the menu bar and the figure head, as well as the height of the task bar at the bottom of the screen by generating a test figure with changing background color and analyzing screen shots of the figure.

getfiguresizeinfo.m

This function calls function computefiguresizeinfo.m and stores the information in a file in a temporary directory. If the figure size information was retrieved once for the current screen size before, it only has to be loaded and the test figure is not needed.

deletefiguresizeinfo.m

If the figure size information saved locally is invalid or outdated (for example due to a change of the task bar height, run function deletefiguresizeinfo.m to delete the stored information.

getscreensizeinpixelspc.c

This is a mex-function which allows to dynamically get the screen size taken from this contribution to Matlab Central. It has to be compiled once on each host. Compilation will be started automatically when the function is needed the first time.

Known issues

The retrieval of the task bar height is expected to work only if the task bar is at the bottom of the screen. Further, the analysis of a screen shot is not extremely "fail-safe". If it fails on your machine, please let me know.

This package does not work under Octave, as the root/figure properties are different.

Contact

Dipl.-Ing. Markus Buehren
Stuttgart, Germany

http://www.markusbuehren.de

Version

Last modified 21.04.2008
Latest version on Matlab Central.

Contact us at files@mathworks.com