1 | %% Axes inside layouts
|
---|
2 | % This example demonstrates how axes are affected by being placed into
|
---|
3 | % layouts. The layouts take into account the "ActivePositionProperty" in
|
---|
4 | % order to determine whether to set the "Position" or "OuterPosition"
|
---|
5 | % (default) property of the axes.
|
---|
6 |
|
---|
7 | %% Open the window
|
---|
8 | % Open a new figure window and remove the toolbar and menus
|
---|
9 | window = figure( 'Name', 'Axes inside layouts', ...
|
---|
10 | 'MenuBar', 'none', ...
|
---|
11 | 'Toolbar', 'none', ...
|
---|
12 | 'NumberTitle', 'off' );
|
---|
13 |
|
---|
14 | %% Create the layout
|
---|
15 | % The layout involves two axes side by side. This is done using a
|
---|
16 | % flexible horizontal box. The left-hand axes is left with the
|
---|
17 | % ActivePositionProperty set to "OuterPosition", but the right-hand axes is
|
---|
18 | % switched to use "Position"
|
---|
19 | hbox = uiextras.HBoxFlex('Parent', window, 'Spacing', 3);
|
---|
20 | axes1 = axes( 'Parent', hbox, ...
|
---|
21 | 'ActivePositionProperty', 'OuterPosition' );
|
---|
22 | axes2 = axes( 'Parent', hbox, ...
|
---|
23 | 'ActivePositionProperty', 'Position' );
|
---|
24 | set( hbox, 'Sizes', [-2 -1] );
|
---|
25 |
|
---|
26 | %% Fill the axes
|
---|
27 | % Using "OuterPosition" (left-hand axes) is the normal mode and looks good
|
---|
28 | % for virtually any plot type. Using "Position" is only really useful for
|
---|
29 | % 2D plots with the axes turned off, such as images
|
---|
30 | x = membrane( 1, 15 );
|
---|
31 | surf( axes1, x );
|
---|
32 | lighting( axes1, 'gouraud' );
|
---|
33 | shading( axes1, 'interp' );
|
---|
34 | l = light( 'Parent', axes1 );
|
---|
35 | camlight( l, 'head' );
|
---|
36 | axis( axes1, 'tight' );
|
---|
37 |
|
---|
38 | imagesc( x, 'Parent', axes2 );
|
---|
39 | set( axes2, 'xticklabel', [], 'yticklabel', [] ); |
---|