The Wayback Machine - https://web.archive.org/web/20110828145330/http://www.mathworks.com:80/help/techdoc/creating_plots/f1-22321.html
Skip to Main Content Skip to Search
Product Documentation

Multiple Axes per Figure

Introduction

The subplot function creates multiple axes in one figure by computing values for Position that produce the specified number of axes.

The subplot function is useful for laying out a number of graphs equally spaced in the figure. However, overlapping axes can create some other useful effects. The following sections provide examples.

Placing Text Outside the Axes

The MATLAB software always displays text objects within an axes. If you want to create a graph and provide a description of the information alongside the graph, you must create another axes to position the text. If you create an axes that is the same size as the figure and then create a smaller axes to draw the graph, you can then display text anywhere independently of the graph.

For example, define two axes.

h = axes('Position',[0 0 1 1],'Visible','off');
axes('Position',[.25 .1 .7 .8])

Because the axes units are normalized to the figure, specifying the Position as [0 0 1 1] creates an axes that encompasses the entire window.

Now plot some data in the current axes. The last axes created is the current axes, so MATLAB directs graphics output there.

t = 0:900;
plot(t,0.25*exp(-0.005*t))

Define the text and display it in the full-window axes.

str(1) = {'Plot of the function:'};
str(2) = {' y = A{\ite}^{-\alpha{\itt}}'};
str(3) = {'With the values:'};
str(3) = {' A = 0.25'};
str(4) = {' \alpha = .005'};
str(5) = {' t = 0:900'};
set(gcf,'CurrentAxes',h)
text(.025,.6,str,'FontSize',12)

Multiple Axes for Different Scaling

You can create multiple axes to display graphics objects with different scaling without changing the data that defines these objects (which would be required to display them in a single axes).

h(1) = axes('Position',[0 0 1 1]);
sphere
h(2) = axes('Position',[0 0 .4 .6]);
sphere
h(3) = axes('Position',[0 .5 .5 .5]);
sphere
h(4) = axes('Position',[.5 0 .4 .4]);
sphere
h(5) = axes('Position',[.5 .5 .5 .3]);
sphere
set(h,'Visible','off')

Each sphere is defined by the same data. However, because the parent axes occupy regions of different size and location, the spheres appear to be different sizes and shapes.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A; sessions led by MATLAB experts.

 © 1984-2011- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS