how to plot two different plots with different axis in a single graph?
조회 수: 3 (최근 30일)
이전 댓글 표시
Vishnuvardhan Naidu Tanga
2021년 10월 25일
댓글: Vishnuvardhan Naidu Tanga
2021년 10월 27일
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.
댓글 수: 0
채택된 답변
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 Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!