Subplots in a single "axes" object
Show older comments
I want to plot 4 graphs using subplot function with 2 x-axes---one on buttom (frequency)---another on top (Strouhal no). I have written following program for that but it is plotting all graphs in same subplot.
Please suggest.
Thank you in advance.
load('data.mat');
figure(1)
ax = axes();
hold(ax);
ax.YAxis.Scale = 'log';
ax.XAxis.Scale = 'log';
%xlabel(ax, 'Frequency (Hz)', 'Interpreter', 'latex', 'FontSize', 14,'FontWeight','Bold');
%ylabel(ax, 'Power spectral density', 'Interpreter', 'latex', 'FontSize', 14,'FontWeight','Bold');
grid on
% setup top axis
ax_top = axes(); % axis to appear at top
hold(ax_top);
ax_top.XAxis.Scale = 'log';
ax_top.XAxisLocation = 'top';
ax_top.YAxisLocation = "right";
ax_top.YTick = [];
% ax_top.XDir = 'reverse';
ax_top.Color = 'none';
%xlabel(ax_top, 'Strouhal number', 'Interpreter', 'latex', 'FontSize', 14,'FontWeight','Bold');
% linking axis
linkprop([ax, ax_top],{'Units','Position','ActivePositionProperty'});
%ax.Position(1,1) = ax.Position(1);
v = 4.687276290832519e+02*12; % inches/sec
c = 16; % inches
f=[0.25 0.5 1 2 4 6 10 16 30 50 100 200 500];
st = f*c./v; % Strouhal number
% configure limits of bottom axis
ax.XLim = [f(1) f(end)];
ax.XTick = f;
ax.XAxis.MinorTick = 'on';
% configure limits and labels of top axis
ax_top.XLim = [st(1) st(end)];
subplot(2,2,1,ax)
plot(fCompnnts(1:end/2),psd3(1:end/2))
subtitle('$x/c=0.448$','Interpreter','latex')
subplot(2,2,2,ax)
plot(fCompnnts(1:end/2),psd4(1:end/2))
subtitle('$x/c=0.498$','Interpreter','latex')
subplot(2,2,3,ax)
plot(fCompnnts(1:end/2),psd5(1:end/2))
subtitle('$x/c=0.542$','Interpreter','latex')
subplot(2,2,4,ax)
plot(fCompnnts(1:end/2),psd8(1:end/2),'-h','Color',[0.6350 0.0780 0.1840])
subtitle('$x/c=0.950$','Interpreter','latex')
Accepted Answer
More Answers (0)
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


