
Panel 2
Layout
The basic layout rule is that panels represent a hierarchy, or tree, of graphics objects. The "root panel" is attached to a Matlab graphics object (usually a figure, though see demopanelD. Each panel, root panel included, may have one or more "child panels". This process is recursive, so that the entire layout under the root panel is a family of panels packed into their respective parents.
Each panel ends up as a "parent panel" (contains child panels) or an "object panel" (contains a graphics object, usually an axis). Newly created panels are "uncommitted" - they become parent panels if you pack() children into them, or become object panels when you select() them.
Packing
Layouts in Panel are governed primarily by "packing". Most panels will be packed in "relative" mode. This means that the space offered by their parent is distributed amongst them according to their packed sizes (fractions of the parent space). "Absolute" packing is also available - see pack(). Panels can be packed along either the horizontal or vertical dimension, so that arbitrarily complex layouts can be built.
Note that you can develop "grid" layouts very succinctly by using the syntax pack(2, 2) (say). See doc panel and pack() for details.
Margins
The other control over layout that you will use frequently is "margins", though this is often only needed as you are finalising the layout for export. Every panel has a margin on each of its four edges. This margin is respected within the panel's parent. For most panels, the parent is the parent panel; for the root panel, the parent is the figure window.
Note that margins are respected only within the immediate parent. For example, the margin setting of the root panel affects the layout of the whole figure with respect to the figure edge, whilst the margin settings of any child panels, grandchild panels, etc., have no impact on the relationship with the figure edge.
Most likely, you will set margins using p(...).margin to set an individual relationship between an individual panel and a sibling, and p(...).de.margin to control the relationships amongst all the descendants of p.
Other aspects of layout
One other factor affecting layout that is rarely needed is the align property - see doc panel. Note, also, that you can get/set margins in a variety of physical units - see the property units.