# How to add 3 x-axies onto a double subplot?

5 visualizzazioni (ultimi 30 giorni)
Wojciech Kalinowski il 20 Nov 2021
Risposto: Dave B il 21 Nov 2021
Hi,
I'm trying to create a subplot with two graph one under eachother; however, I want each to have 3 x-axies.
I'm doing some basic aircraft tail modeling and on the x-axies I want to have:
• the span (b) in meters
• the Aspect Ratio (AR) for sailplane
• the AR for twin engine
For a horizontal and vertical tail hence the subplot.
I have an array for the span a 1x500 array in meters.
To convert to the AR I need to use the formula:
Where there are two different areas, denoted as S. In matlab S_VT 2x1 array (sailplane and twin engine) and S_HT 2x1 array (sailplane and twin engine) .
Currently I have a plot like:
My current code:
b = linspace(1,5,500);
c_rVT = 2.*S_VT./(b.*(1+taper(1)));
c_rHT = 2.*S_HT./(b.*(1+taper(2)));
c_tVT = taper(1).*c_rVT;
c_tHT = taper(2).*c_rHT;
% plotting
figure(2);
subplot(2,1,1);
ax1 = axes('Position', [.1 .1 .8 1e-12]);
ax2 = axes('Position',[.1 .2 .8 .7]);
set(ax1,'Units','normalized');
set(ax2,'Units','normalized');
stem(ax2, b.^2./S_VT(1), c_rVT(1,:));
set(ax1,'xlim',[b(1)^2/S_VT(1) b(end)^2/S_VT(1)]);
plot(b,c_rVT(1,:),'-b', b,c_rVT(2,:),'-r',...
b,c_tVT(1,:),'--b', b,c_tVT(2,:),'--r');
title("Vertical tail platform sizing");
xlabel(ax2,"b in m"); xlabel(ax1, "AR");
ylabel(ax1,"chords in m");
legend("root chord (sailplane)", "root chord (twin engin)",...
"tip chord (sailplane)", "tip chord (twin engin)");
How can I add another x axies (and idealy put both the AR axies at the top of each plot) on both subplotts?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Dave B il 21 Nov 2021
You can sort of fake this kind of thing with TiledChartLayout. The layout will keep your axes lined up.
Starting simple, with just one additional axis:
figure(1);
t=tiledlayout(1,1);
plotax=axes(t);
plot(plotax,rand(1,10));
xax1=axes(t); % make an axes in the layout
xax1.Layout.Tile='South'; % Put it in the 'South' tile
xax1.PlotBoxAspectRatio=[1 eps 1]; % Set the PlotBoxAspectRatio so that it's very narrow
xlim(xax1,[0 100]) % Set limits, ticks, labels however you normally would
Expanding this technique to do two additional axes isn't too hard, because you can nest one layout inside another.
figure(2);
t=tiledlayout(1,1);
plotax=axes(t);
plot(plotax,rand(1,10));
% make a layout that goes in the south tile of the main layout.
% This one will hold two axes
taxes = tiledlayout(2,1,'Parent',t);
taxes.Layout.Tile = 'South';
xax1=nexttile(taxes); % shortcut for xax1=axes(taxes); xax1.Layout.Tile=1;
xax1.PlotBoxAspectRatio=[1 eps 1];
xlim(xax1,[0 100])
xax2=nexttile(taxes); % shortcut for xax1=axes(taxes); xax1.Layout.Tile=2;
xax2.PlotBoxAspectRatio=[1 eps 1];
xlim(xax2,[0 pi])
Moving them to the top isn't so bad, beyond just putting them in the nort tile, you can also change which side (of their infinitely narrow axes) they're displayed on:
figure(3);
t=tiledlayout(1,1);
plotax=axes(t);
plot(plotax,rand(1,10));
% make a layout that goes in the south tile of the main layout.
% This one will hold two axes
taxes = tiledlayout(2,1,'Parent',t);
taxes.Layout.Tile = 'North';
xax1=nexttile(taxes); % shortcut for xax1=axes(taxes); xax1.Layout.Tile=1;
xax1.PlotBoxAspectRatio=[1 eps 1];
xax1.XAxisLocation = 'top';
xlim(xax1,[0 100])
xax2=nexttile(taxes); % shortcut for xax1=axes(taxes); xax1.Layout.Tile=2;
xax2.PlotBoxAspectRatio=[1 eps 1];
xax2.XAxisLocation = 'top';
xlim(xax2,[0 pi])
• You can adjust the Padding and TileSpacing properties on the TiledChartLayout object to tighten it up a bit if that's what you like.
• You can put the whole thing into a tile of another layout, e.g. if you have two of this entire thing side-by-side. Layouts are infinitely nestable (although things get too small to be useful after a few layers).
• If you want to make it so that things adjust appropriately when you zoom in and out, things get significantly more complicated...but it's not necessarily impossible.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Graphics Object Properties in Help Center e File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by