How to plot multiple graphs with same x-axis?
조회 수: 29 (최근 30일)
이전 댓글 표시
I have to draw 8 figures seperately but in a same graph for comparsion (same x-axis and differnt y-axis). I have used the code mentioned below. However, I am able to draw this for only 2 figures (figure attached). I want to do this same with 8 figures. Can anyone kindly, let me know what changes I have to make in the code so that it works for all the figures not just 2 figures.

if true
% figure(1)
x1=subplot(2,1,1);
stairs(DDr.Var1,DDr.Var2);
legend('Station 1 LHS')
ylabel('Cycle time')
title('Station 1 RHS & LHS hourly mean cycle time')
set(gca,'XTickLabel',[]);
ylim([0 105]);
x2=subplot(2,1,2);
stairs(DDr.Var1,DDr.Var3);
ylabel('Cycle time')
legend(' Station 1 RHS')
ylim([0 105]);
p1 = get(x1, 'Position');
p2 = get(x2, 'Position');
p1(2) = p2(2)+p2(4);
set(x1, 'pos', p1);
xlabel('Time')
end
댓글 수: 1
Mohamed Elnagdy
2021년 9월 16일
it's because you have specified the number of graphs to be two in this line ''x1=subplot(2,1,1);
the first number is refered to as m in matlab's documentation, if you need 8, the replace the 2 with 8 and rearrange your plots as you wish
채택된 답변
Steven Lord
2018년 10월 18일
If you're using release R2018b or later, consider using stackedplot. There's an example on that page, "Change Individual Plots to Scatter and Stair Plots", showing how to change the plots into stairs plots.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!