how to plot two different plots with different axis in a single graph?

4 ビュー (過去 30 日間)
Hello everyone,
I am trying to plot two different plots in a single plot with two different Y- axis but on same same X axis. Is there any way to plot. I am attaching the data and an image of what i required. The data for the second plot is in plot2 excel file. Please kindly help me.
My code:
Z = readtable('Atq100_2.xlsx') ;
Y = readtable('plot2.xlsx') ;
data = table2array(Z) ;
N = size(data,2);
Nsp = N/2;
ttlc = {'x=10mm', 'x=250mm', 'x=500mm', 'x=1000mm', 'x=1500mm'};
xofst = [10 250 500 1000 1500];
figure
ylim([-1 1]*250)
xlim([0 1750])
hold on
for k = 1:Nsp
col = [2 1]+2*(k-1);
famp = 5; % Amplification Factor
datacol1 = data(:,col(1))*famp+xofst(k);
hp(k) = plot(datacol1, data(:,col(2)), 'LineWidth',2);
% plot(data(:,col(1))+xofst(k), data(:,col(2)), 'LineWidth',2)
% minx = min(data(:,col(1))+xofst(k));
% maxx = max(data(:,col(1))+xofst(k));
minx(k) = min(datacol1);
maxx(k) = max(datacol1);
plot([1;1]*[minx(k) maxx(k)], ([1;1]*ylim).', ':k', 'LineWidth',1) % Plot Vertical 'scale' Lines
% plot([1;1]*[minx], ([1;1]*ylim).', ':k', 'LineWidth',1) % Plot Vertical 'scale' Lines
plot([minx(1) maxx(1)]-minx(1)+minx(k), [0 0], '-k', 'LineWidth',1) % Plot Horizontal 'zero' Lines
Line_Coordinates = [minx(1) maxx(1)]-minx(1)+minx(k);
LineLength = diff(Line_Coordinates);
end
hold off
hl = legend([hp], ttlc, 'Location','northeastoutside');
Thanks in advance.

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 10 月 25 日
Have a look at the documentation and help for yyaxis. There you should find illustrating examples doing what you want. Possibly in combination with subplot or tiledlayout/nexttile to generate multiple axes to plot in.
HTH

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by