Combine Multiple Plots - MATLAB & Simulink - MathWorks France (2024)

Since R2019b. Replaces Combine Multiple Plots (R2019a).

Open Live Script

This example shows how to combine plots in the same axes using the hold function, and how to create multiple axes in a figure using the tiledlayout function.

Combine Plots in Same Axes

By default, new plots clear existing plots and reset axes properties, such as the title. However, you can use the hold on command to combine multiple plots in the same axes. For example, plot two lines and a scatter plot. Then reset the hold state to off.

x = linspace(0,10,50);y1 = sin(x);plot(x,y1)title('Combine Plots')hold ony2 = sin(x/2);plot(x,y2)y3 = 2*sin(x);scatter(x,y3) hold off

Combine Multiple Plots- MATLAB & Simulink- MathWorks France (1)

When the hold state is on, new plots do not clear existing plots or reset axes properties, such as the title or axis labels. The plots cycle through colors and line styles based on the ColorOrder and LineStyleOrder properties of the axes. The axes limits and tick values might adjust to accommodate new data.

Display Multiple Axes in a Figure

You can display multiple axes in a single figure by using the tiledlayout function. This function creates a tiled chart layout containing an invisible grid of tiles over the entire figure. Each tile can contain an axes for displaying a plot. After creating a layout, call the nexttile function to place an axes object into the layout. Then call a plotting function to plot into the axes. For example, create two plots in a 2-by-1 layout. Add a title to each plot.

x = linspace(0,10,50);y1 = sin(x);y2 = rand(50,1);tiledlayout(2,1)% Top plotnexttileplot(x,y1)title('Plot 1')% Bottom plotnexttilescatter(x,y2)title('Plot 2')

Combine Multiple Plots- MATLAB & Simulink- MathWorks France (2)

Create Plot Spanning Multiple Rows or Columns

To create a plot that spans multiple rows or columns, specify the span argument when you call nexttile. For example, create a 2-by-2 layout. Plot into the first two tiles. Then create a plot that spans one row and two columns.

x = linspace(0,10,50);y1 = sin(x);y2 = rand(50,1);% Top two plotstiledlayout(2,2)nexttileplot(x,y1)nexttilescatter(x,y2)% Plot that spansnexttile([1 2])y2 = rand(50,1);plot(x,y2)

Combine Multiple Plots- MATLAB & Simulink- MathWorks France (3)

Modify Axes Appearance

Modify the axes appearance by setting properties on each of the axes objects. You can get the axes object by calling the nexttile function with an output argument. You also can specify the axes object as the first input argument to a graphics function to ensure that the function targets the correct axes.

For example, create two plots and assign the axes objects to the variables ax1 and ax2. Change the axes font size and x-axis color for the first plot. Add grid lines to the second plot.

x = linspace(0,10,50);y1 = sin(x);y2 = rand(50,1);tiledlayout(2,1)% Top plotax1 = nexttile;plot(ax1,x,y1)title(ax1,'Plot 1')ax1.FontSize = 14;ax1.XColor = 'red';% Bottom plotax2 = nexttile;scatter(ax2,x,y2)title(ax2,'Plot 2')grid(ax2,'on')

Combine Multiple Plots- MATLAB & Simulink- MathWorks France (4)

Control Spacing Around the Tiles

You can control the spacing around the tiles in a layout by specifying the Padding and TileSpacing properties. For example, display four plots in a 2-by-2 layout.

x = linspace(0,30);y1 = sin(x);y2 = sin(x/2);y3 = sin(x/3);y4 = sin(x/4);% Create plotst = tiledlayout(2,2);nexttileplot(x,y1)nexttileplot(x,y2)nexttileplot(x,y3)nexttileplot(x,y4)

Reduce the spacing around the perimeter of the layout and around each tile by setting the Padding and TileSpacing properties to 'compact'.

t.Padding = 'compact';t.TileSpacing = 'compact';

Combine Multiple Plots- MATLAB & Simulink- MathWorks France (6)

Display Shared Title and Axis Labels

You can display a shared title and shared axis labels in a layout. Create a 2-by-1 layout t. Then display a line plot and a stem plot. Synchronize the x-axis limits by calling the linkaxes function.

x1 = linspace(0,20,100);y1 = sin(x1);x2 = 3:17;y2 = rand(1,15);% Create plots.t = tiledlayout(2,1);ax1 = nexttile;plot(ax1,x1,y1)ax2 = nexttile;stem(ax2,x2,y2)% Link the axeslinkaxes([ax1,ax2],'x');

Combine Multiple Plots- MATLAB & Simulink- MathWorks France (7)

Add a shared title and shared axis labels by passing t to the title, xlabel, and ylabel functions. Move the plots closer together by removing the x-axis tick labels from the top plot and setting the TileSpacing property of t to 'compact'.

% Add shared title and axis labelstitle(t,'My Title')xlabel(t,'x-values')ylabel(t,'y-values')% Move plots closer togetherxticklabels(ax1,{})t.TileSpacing = 'compact';

Combine Multiple Plots- MATLAB & Simulink- MathWorks France (8)

See Also

Functions

  • tiledlayout | nexttile | title | hold

Related Topics

  • Create Chart with Two y-Axes
  • Specify Axis Tick Values and Labels

Commande MATLAB

Vous avez cliqué sur un lien qui correspond à cette commande MATLAB:

 

Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.

Combine Multiple Plots- MATLAB & Simulink- MathWorks France (9)

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

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Combine Multiple Plots
- MATLAB & Simulink
- MathWorks France (2024)
Top Articles
10 Healthier Holiday Cookie Recipes Under 135 Calories
37 Recipes for Thanksgiving Day In Your RV
Katie Nickolaou Leaving
Friskies Tender And Crunchy Recall
123Movies Encanto
Collision Masters Fairbanks
Botanist Workbench Rs3
Www.megaredrewards.com
Lenscrafters Westchester Mall
What's Wrong with the Chevrolet Tahoe?
Over70Dating Login
Natureza e Qualidade de Produtos - Gestão da Qualidade
Brenna Percy Reddit
10 Great Things You Might Know Troy McClure From | Topless Robot
Palace Pizza Joplin
Craigslist Farm And Garden Cincinnati Ohio
Ukc Message Board
H12 Weidian
Energy Healing Conference Utah
Pjs Obits
Jenna Ortega’s Height, Age, Net Worth & Biography
R. Kelly Net Worth 2024: The King Of R&B's Rise And Fall
Craigslistodessa
Southwest Flight 238
Carroway Funeral Home Obituaries Lufkin
NV Energy issues outage watch for South Carson City, Genoa and Glenbrook
Biografie - Geertjan Lassche
Jazz Total Detox Reviews 2022
Mississippi Craigslist
Craftsman Yt3000 Oil Capacity
How to Use Craigslist (with Pictures) - wikiHow
3473372961
What are the 7 Types of Communication with Examples
Gerber Federal Credit
Worlds Hardest Game Tyrone
24 slang words teens and Gen Zers are using in 2020, and what they really mean
Chattanooga Booking Report
Best Workers Compensation Lawyer Hill & Moin
Stanford Medicine scientists pinpoint COVID-19 virus’s entry and exit ports inside our noses
Gpa Calculator Georgia Tech
Zasilacz Dell G3 15 3579
Wasmo Link Telegram
Shipping Container Storage Containers 40'HCs - general for sale - by dealer - craigslist
Royals Yankees Score
Atu Bookstore Ozark
22 Golden Rules for Fitness Beginners – Barnes Corner Fitness
Victoria Vesce Playboy
Walmart Front Door Wreaths
Steam Input Per Game Setting
Strange World Showtimes Near Atlas Cinemas Great Lakes Stadium 16
Hsi Delphi Forum
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 6554

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.