Create axes in tiled chart layout (2024)

Create axes in tiled chart layout

Since R2019b

collapse all in page

Syntax

nexttile

nexttile(span)

nexttile(tilelocation)

nexttile(tilelocation,span)

nexttile(t,___)

ax = nexttile(___)

Description

example

nexttile creates an axes object and places it into the next empty tile of the tiled chart layout that is in the current figure. If there is no layout in the current figure, then nexttile creates a new layout and configures it using the 'flow' tile arrangement. The resulting axes object is the current axes, so the next plotting command can plot into it.

example

nexttile(span) creates an axes object that spans across multiple rows or columns of the grid in the center of the layout. Specify span as a vector of the form [r c]. The axes spans r rows by c columns of tiles. The upper left corner of the axes is positioned in the upper left corner of the first empty r-by-c region in the grid.

example

nexttile(tilelocation) assigns the current axes to be the axes or standalone visualization in the tile specified by tilelocation. Typically, this syntax is useful when you want to modify an existing axes or standalone visualization. However, in some cases, nexttile creates a new axes object:

  • When the specified tile is empty, nexttile creates an axes object in that tile.

  • When the specified tile contains part of an axes or standalone visualization object, but not its upper left corner, nexttile replaces the existing object. For example, if tilelocation refers to a tile in the middle of an axes object that spans multiple tiles, nexttile replaces the existing axes object with a new one in the tile you specify.

example

nexttile(tilelocation,span) creates an axes object that spans across multiple rows or columns, starting at the tile specified by tilelocation. If the tile you specify is occupied by an axes or standalone visualization, nexttile either makes that object the current axes or replaces it:

  • If the existing axes or standalone visualization object spans across the same set of tiles as the tilelocation and span arguments specify, then nexttile makes that object the current axes.

  • If the existing axes or standalone visualization object spans across a different set of tiles than the tilelocation and span arguments specify, then nexttile replaces the existing object with a new axes object using the new tilelocation and span values.

example

nexttile(t,___) operates on the tiled chart layout specified by t. Specify t before all other input arguments. This syntax is useful when you are working with multiple layouts, or when the layout is in a panel or tab instead of a figure.

example

ax = nexttile(___) returns the axes object. Use ax to set properties on the axes. You can also pass ax as an input argument to other graphics functions that operate on an axes object. For example, you can call the colormap or colororder function to change the color scheme for the axes.

Examples

collapse all

Create Flow Layout

Open Live Script

If a tiled chart layout does not already exist, nexttile creates one.

Create four coordinate vectors: x, y1, y2, and y3.

Call the nexttile function to create a tiled chart layout and an axes object in the first tile. Then plot y1 in the first tile. This first plot fills the entire layout because nexttile creates the layout using the 'flow' tile arrangement.

x = linspace(0,30);y1 = sin(x/2);y2 = sin(x/3);y3 = sin(x/4);% Create layout and first plotnexttileplot(x,y1)

Create axes in tiled chart layout (1)

Create a second tile and axes, and plot into the axes.

nexttileplot(x,y2)

Create axes in tiled chart layout (2)

Repeat the process to create a third plot.

nexttileplot(x,y3)

Create axes in tiled chart layout (3)

Repeat the process to create a fourth plot. This time, plot all three lines in the same axes by calling hold on after plotting y1.

nexttileplot(x,y1)hold onplot(x,y2)plot(x,y3)hold off

Create axes in tiled chart layout (4)

Plot Into 2-by-2 Layout

Open Live Script

Call the tiledlayout function to create a 2-by-2 tiled chart layout, and call the peaks function to get the coordinates of a predefined surface. Create an axes object in the first tile by calling the nexttile function. Then call the surf function to plot into the axes. Repeat the process using different plotting functions for the other three tiles.

tiledlayout(2,2);[X,Y,Z] = peaks(20);% Tile 1nexttilesurf(X,Y,Z)% Tile 2nexttilecontour(X,Y,Z)% Tile 3nexttileimagesc(Z)% Tile 4nexttileplot3(X,Y,Z)

Create axes in tiled chart layout (5)

Create Vertical Stack of Plots

Open Live Script

Create a tiled chart layout that has a vertical stack of plots by specifying the "vertical" option when you call the tiledlayout function. Then create three plots by calling the nexttile function followed by a plotting function. Each time you call nexttile, a new axes object is added to the bottom of the stack.

tiledlayout("vertical")x = 0:0.1:5;nexttileplot(x,sin(x))nexttileplot(x,sin(x+1))nexttileplot(x,sin(x+2))

Create axes in tiled chart layout (6)

Create Horizontal Stack of Plots

Open Live Script

Create a tiled chart layout that has a horizontal stack of plots by specifying the "horizontal" option when you call the tiledlayout function. Then create three plots by calling the nexttile function followed by a plotting function. Each time you call nexttile, a new axes object is added to the right side of the stack.

tiledlayout("horizontal")x = 0:0.1:10;nexttileplot(x,sin(x/2))nexttileplot(x,sin(x))nexttileplot(x,sin(2*x))

Create axes in tiled chart layout (7)

Set Properties on the Axes

Open Live Script

Call the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function with an output argument to store the axes. Then plot into the axes, and set the x- and y-axis colors to red. Repeat the process in the second tile.

t = tiledlayout(2,1);% First tileax1 = nexttile;plot([1 2 3 4 5],[11 6 10 4 18]);ax1.XColor = [1 0 0];ax1.YColor = [1 0 0];% Second tileax2 = nexttile;plot([1 2 3 4 5],[5 1 12 9 2],'o');ax2.XColor = [1 0 0];ax2.YColor = [1 0 0];

Create axes in tiled chart layout (8)

Create Axes That Span Multiple Rows and Columns

Open Live Script

Define scores and strikes as vectors containing bowling league data over four games. Then create a tiled chart layout and display three plots showing the number of strikes for each team.

scores = [444 460 380 387 366 500 365 451 611 548 412 452];strikes = [9 6 5 6 4 8 4 7 16 10 9 8]; t = tiledlayout('flow');% Team 1nexttileplot([1 2 3 4],strikes(:,1),'-o')title('Team 1 Strikes')% Team 2nexttileplot([1 2 3 4],strikes(:,2),'-o')title('Team 2 Strikes')% Team 3nexttileplot([1 2 3 4],strikes(:,3),'-o')title('Team 3 Strikes')

Create axes in tiled chart layout (9)

Call the nexttile function to create an axes object that spans two rows by three columns. Then display a bar graph in the axes with a legend, and configure the axis tick values and labels. Call the title function to add a tile to the layout.

nexttile([2 3]);bar([1 2 3 4],scores)legend('Team 1','Team 2','Team 3','Location','northwest')% Configure ticks and axis labelsxticks([1 2 3 4])xlabel('Game')ylabel('Score')% Add layout titletitle(t,'April Bowling League Data')

Create axes in tiled chart layout (10)

Span Axes at Specific Tile Number

Open Live Script

To span an axes object from a specific location, specify the tile number and the span value.

Define scores and strikes as vectors containing bowling league data over four games. Then create a 3-by-3 tiled chart layout and display five bar graphs showing the number of strikes for each team.

scores = [444 460 380 388 389 387 366 500 467 460 365 451 611 426 495 548 412 452 471 402];strikes = [9 6 5 7 5 6 4 8 10 7 4 7 16 9 9 10 9 8 8 9]; t = tiledlayout(3,3);% Team 1nexttilebar([1 2 3 4],strikes(:,1))title('Team 1 Strikes')% Team 2nexttilebar([1 2 3 4],strikes(:,2))title('Team 2 Strikes')% Team 3nexttilebar([1 2 3 4],strikes(:,3))title('Team 3 Strikes')% Team 4nexttilebar([1 2 3 4],strikes(:,4))title('Team 4 Strikes')% Team 5nexttile(7)bar([1 2 3 4],strikes(:,5))title('Team 5 Strikes')

Create axes in tiled chart layout (11)

Display a larger plot with a legend. Call the nexttile function to place the upper left corner of the axes in the fifth tile, and span the axes across two rows by two columns of tiles. Plot the scores for all the teams. Configure the x-axis to display four ticks, and add labels to each axis. Then add a shared title at the top of the layout.

nexttile(5,[2 2]);plot([1 2 3 4],scores,'-.')labels = {'Team 1','Team 2','Team 3','Team 4','Team 5'};legend(labels,'Location','northwest')% Configure ticks and axis labelsxticks([1 2 3 4])xlabel('Game')ylabel('Score')% Add layout titletitle(t,'April Bowling League Data')

Create axes in tiled chart layout (12)

Display Polar and Geographic Plots

Create a 1-by-2 tiled chart layout. In the first tile, display a geographic plot containing a line that connects two cities on a map. In the second tile, create a scatter plot in polar coordinates.

tiledlayout(1,2)% Display geographic plotnexttilegeoplot([47.62 61.20],[-122.33 -149.90],'g-*')% Display polar plotnexttiletheta = pi/4:pi/4:2*pi;rho = [19 6 12 18 16 11 15 15];polarscatter(theta,rho)

Create axes in tiled chart layout (13)

Reconfigure Content in Previous Tile

Open Live Script

One of the ways that the nexttile output argument is useful is when you want to adjust the content in a previous tile. For example, you might decide to reconfigure the colormap used in a previous plot.

Create a 2-by-2 tiled chart layout. Call the peaks function to get the coordinates for a predefined surface. Then create a different plot of the surface in each tile.

tiledlayout(2,2);[X,Y,Z] = peaks(20);% Tile 1nexttilesurf(X,Y,Z)% Tile 2nexttilecontour(X,Y,Z)% Tile 3nexttileimagesc(Z)% Tile 4nexttileplot3(X,Y,Z)

Create axes in tiled chart layout (14)

To change the colormap in the third tile, get the axes in that tile. Call the nexttile function by specifying the tile number, and return the axes output argument. Then pass the axes to the colormap function.

ax = nexttile(3);colormap(ax,cool)

Create axes in tiled chart layout (15)

Reconfigure Spanned Axes

Open Live Script

Create a 2-by-3 tiled chart layout containing two plots in individual tiles, and one plot that spans across two rows and two columns.

t = tiledlayout(2,3);[X,Y,Z] = peaks;% Tile 1nexttilecontour(X,Y,Z)% Span across two rows and columnsnexttile([2 2])contourf(X,Y,Z)% Last tilenexttileimagesc(Z)

Create axes in tiled chart layout (16)

To change the colormap for the spanned axes, identify the tile location as one containing the upper-left corner of the axes. In this case, the upper-left corner is in the second tile. Call the nexttile function with 2 as tile location, and specify an output argument to return the axes object at that location. Then pass the axes to the colormap function.

ax = nexttile(2);colormap(ax,hot)

Create axes in tiled chart layout (17)

Replace Content in Previous Tile

Open Live Script

Load the patients data set and create a table from a subset of the variables. Then create a 2-by-2 tiled chart layout. Display a scatter plot in the first tile, a heatmap in the second tile, and a stacked plot across the bottom two tiles.

load patientstbl = table(Diastolic,Smoker,Systolic,Height,Weight,SelfAssessedHealthStatus);tiledlayout(2,2)% Scatter plotnexttilescatter(tbl.Height,tbl.Weight)% Heatmapnexttileheatmap(tbl,'Smoker','SelfAssessedHealthStatus','Title','Smoker''s Health');% Stacked plotnexttile([1 2])stackedplot(tbl,{'Systolic','Diastolic'});

Create axes in tiled chart layout (18)

Call nexttile, and specify the tile number as 1 to make the axes in that tile the current axes. Replace the contents of that tile with a scatter histogram.

nexttile(1)scatterhistogram(tbl,'Height','Weight');

Create axes in tiled chart layout (19)

Display Shared Colorbar in Separate Tile

Open Live Script

When you want to share a colorbar or legend between two or more plots, you can place it in a separate tile.

Create filled contour plots of the peaks and membrane data sets in a tiled chart layout.

Z1 = peaks;Z2 = membrane;tiledlayout(2,1);nexttilecontourf(Z1)nexttilecontourf(Z2)

Create axes in tiled chart layout (20)

Add a colorbar, and move it to the east tile.

cb = colorbar;cb.Layout.Tile = 'east';

Create axes in tiled chart layout (21)

Display Layout in a Panel

Open Live Script

Create a panel in a figure. Then create a tiled chart layout t in the panel by specifying the panel object as the first argument to the tiledlayout function. By default, nexttile looks for the layout in the figure. However the layout is in a panel instead of a figure, so you must specify t as an input argument when you call nexttile.

p = uipanel('Position',[.1 .2 .8 .6]);t = tiledlayout(p,2,1);% Tile 1nexttile(t)stem(1:13)% Tile 2nexttile(t)bar([10 22 31 43 52])

Create axes in tiled chart layout (22)

Create Axes Without nexttile and Position it Manually

Open Live Script

Occasionally, you might need to create the axes by calling one of the axes functions (axes, polaraxes, or geoaxes). When you create the axes with one of these functions, specify the parent argument as the tiled chart layout. Then position the axes by setting the Layout property on the axes.

Create a tiled chart layout t and specify the 'flow' tile arrangement. Display a plot in each of the first three tiles.

t = tiledlayout('flow');nexttileplot(rand(1,10));nexttileplot(rand(1,10));nexttileplot(rand(1,10));

Create axes in tiled chart layout (23)

Create a geographic axes object gax by calling the geoaxes function and specify t as the parent argument. By default, the axes goes into the first tile, so move it to the fourth tile by setting gax.Layout.Tile to 4. Span the axes across a 2-by-3 region of tiles by setting gax.Layout.TileSpan to [2 3].

gax = geoaxes(t);gax.Layout.Tile = 4;gax.Layout.TileSpan = [2 3];

Create axes in tiled chart layout (24)

Call the geoplot function. Then configure the map center and zoom level for the axes.

geoplot(gax,[47.62 61.20],[-122.33 -149.90],'g-*')gax.MapCenter = [47.62 -122.33];gax.ZoomLevel = 2;

Create axes in tiled chart layout (25)

Input Arguments

collapse all

tilelocationTile location
positive whole number | 'north' | 'south' | 'east' | 'west'

Tile location, specified one of the values from the table.

The labeled rectangles in the following examples illustrate the tiles in the grid and the outer tiles of a layout with the default TileIndexing scheme. In practice, the grid is invisible and the outer tiles do not take up space until you populate them with axes. The rectangles with thicker borders reflect the selected tile in each example.

tilelocationDescriptionExample
Positive whole numberOne of the tiles from the grid in the center of the layout. By default, the tile numbers start at 1 and increase from left-to-right and top-to-bottom.

Create a 2-by-2 layout and select the third tile in the grid.

tiledlayout(2,2)nexttile(3)

Create axes in tiled chart layout (26)

'north', 'south', 'east', or 'west'One of the tiles around the outside of the grid.

Create a 2-by-2 layout and select the east tile, which is to the right of the grid.

tiledlayout(2,2)nexttile('east')

Create axes in tiled chart layout (27)

Note

If the tile you specify is empty, nexttile places an axes object into that tile. If the tile contains an axes object or standalone visualization, then that object becomes the current axes, so the next plotting command can plot into that tile.

spanTile span
[1 1] (default) | [r c]

Tile span, specified as a vector of the form [r c], where r and c are positive whole numbers. Use this argument to make the axes span r rows by c columns of tiles in the layout.

If you specify the span argument without the tilelocation argument, nexttile places the upper left corner of the axes in the upper left corner of the first empty r-by-c region in the layout.

However, if you specify both the tilelocation and span arguments, nexttile places the upper left corner of the axes in the upper left corner of the tile specified by tilelocation. For example, the large axes on the right side of this 3-by-4 layout has a tile number of 2 and a span of [2 3].

Create axes in tiled chart layout (28)

tTiled chart layout
TiledChartLayout object

TiledChartLayout object to place the axes into. This argument is useful when you are working with multiple layouts, or when the layout is in a panel or tab instead of a figure. When you do not specify t, nexttile looks for the layout in the current figure.

Version History

Introduced in R2019b

See Also

Functions

  • tiledlayout | tilenum | tilerowcol

Properties

  • TiledChartLayout Properties

Topics

  • Combine Multiple Plots
  • Customized Presentations and Special Effects with Tiled Chart Layouts

MATLAB-Befehl

Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:

 

Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.

Create axes in tiled chart layout (29)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Create axes in tiled chart layout (2024)

References

Top Articles
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated:

Views: 5854

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.