How can I create and arrange multiple axes in the same figure in MATLAB?

39 Ansichten (letzte 30 Tage)
How can I create and arrange multiple axes in the same figure in MATLAB?
I would like to place multiple axes in the same figure. What functions or code will allow me to specify the locations of the axes in the figure?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 27 Jun. 2009
There are two basic techniques used to control the positioning of multiple axes:
1) Setting the Position property of the axes manually
2) Using SUBPLOT
These techniques should not be used together, because SUBPLOT will delete any axes that the new subplot axes would overlap. Therefore, unless you are certain that the axes won't overlap, you should only use one of the techniques.
Using the first method, you can create as many axes as you want in the same figure, and they will not disappear, regardless of whether they overlap. You can create axes in a specific figure by passing its handle as an input parameter when you create the axes:
f = figure;
ax1 = axes('Parent',f);
If you don't specify the Parent, then the current figure is used, or a figure is created and used if there are not any figures open.
You specify the positioning of the axes, either on creation or later, by setting its Position property:
ax2 = axes('Parent',f,'Units','normalized','Position',[.2 .2 .6 .3]);
ax3 = axes('Parent',f);
set(ax3,'Units','normalized','Position',[.5 .6 .3 .3]);
When you use SUBPLOT to create axes, the function will determine whether any portion of the new axes will overlap existing axes in the current figure, and will remove the old axes that would have been covered. If there isn't a figure available, one will be created.
The first inputs to SUBPLOT specify the dimensions of a grid, and the third specifies a location in the grid. For example,
subplot(3,4,7)
places an axes at the seventh location in a grid with 3 rows and 4 columns. The locations are numbered left to right across the rows, so the 1 through 4 corresponds to the first row, 5 through 8 is the second row, and 9 through 12 is the third row.
Instead of simply specifying a single location for the axes to occupy, you could use SUBPLOT to select a grid of elements to cover:
subplot(4,4,1:4);
This will cover the first four positions that these subplots would have covered:
figure
subplot(4,4,1);
subplot(4,4,2);
subplot(4,4,3);
subplot(4,4,4);
You could also use different arrangements. When creating a 4 by 4 subplot, the subplot locations match this grid:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Try the following code:
figure
subplot(4,4, [1 2 3 5 6 7])
subplot(4,4, [4 8 12 16])
subplot(4,4, [9 10 13 14])
subplot(4,4, [11 15])
Each subplot will cover the locations in the vector you specified as the third argument. If you use this method, you'll probably want to experiment with the number of subplots and the range to cover, to obtain the exact layout you want.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by