Tiledlayout: Make Plots of unequal width

37 次查看(过去 30 天)
Hello,
I want to use tiledlayout to place multiple graphs of unequal width. An example of what I'm trying to do is below. Using the figure command only seems to edit the entire box and I'm not sure how to make the tiledlayout command do what I want
Current figure:
Desired appearance (expertly edited using MS Paint)
Example code:
figure('Units','normalized','Position',[0.5,0.4,.5,.5]);
tiledlayout(1,2,'TileSpacing','Compact','Padding','Compact')
nexttile
plot(foo,bar)
%formatting stuff
nexttile
plot (foo2,bar2)
%formatting stuff

采纳的回答

Mann Baidi
Mann Baidi 2024-6-13
编辑:Mann Baidi 2024-6-13
I can observe that you would like to plot graphs with unequal width using "tiledlayout".
For plotting graph with unequal width, you will have to consider the figure as m x n matrices and then give width and height to different graphs accordingly. For your issue, you can refer to the following example.
% Create a 2x3 tiled layout
t = tiledlayout(2, 3);
% First plot (spans 2 rows and 1 column)
nexttile(t, [2, 1]);
plot(rand(10, 1));
title('Plot 1 (2 rows x 1 column)');
% Second plot (spans 2 rows and 2 columns)
nexttile(t, [2, 2]);
plot(rand(10, 1));
title('Plot 2 (1 row x 2 columns)');
You can explore more about tiledlayout using the link mentioned below:

更多回答(1 个)

Tony
Tony 2024-6-13
If your sizing is small integer ratios, then you can control the size of the group of tiles the individual plots span
plot_spans = [2 1 ; 2 2]; % first plot is half as wide as second
figure('Units','normalized','Position',[0.5,0.4,.5,.5]);
tiledlayout(max(plot_spans(:,1)), sum(plot_spans(:,2)), 'TileSpacing','Compact','Padding','Compact')
nexttile(plot_spans(1,:)) % number of rows and columns the plot should span
%plot(foo,bar)
%formatting stuff
nexttile(plot_spans(2,:))
%plot (foo2,bar2)
%formatting stuff

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by