Tiledlayout: Make Plots of unequal width
43 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthew
am 13 Jun. 2024
Bearbeitet: Mann Baidi
am 13 Jun. 2024
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:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1714631/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1714631/image.png)
Desired appearance (expertly edited using MS Paint)![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1714636/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1714636/image.png)
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
0 Kommentare
Akzeptierte Antwort
Mann Baidi
am 13 Jun. 2024
Bearbeitet: Mann Baidi
am 13 Jun. 2024
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:
0 Kommentare
Weitere Antworten (1)
Tony
am 13 Jun. 2024
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!