Changing subplot x limit
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to create 2 subplots in a figure, theta_1 vs. t and theta_2 vs. t. The range of t in both plots is 10. There are the same amount of data points in both plots. When I run the code however, the second subplot's range of t is increased
This is my code:
figure(1)
grid on
P1 = subplot(2,1,1)
plot(t,v(1,:),'linewidth',2)
xlabel('t','fontSize',14);
ylabel('\theta_1','fontSize',14);
P2 = subplot(2,1,2)
plot(t,v(2,:),'r','linewidth',2)
h=gca;
get(h,'fontSize')
set(h,'fontSize',14)
xlabel('t','fontSize',14);
ylabel('\theta_2','fontSize',14);
xlim(P2, [0 10]);%trying to specify xlim
fh = figure(1);
set(fh, 'color', 'white');
I even tried to specify the xlim for the second subplot but it made no difference. What am I doing wrong?
댓글 수: 3
dpb
2021년 1월 27일
h=gca;
get(h,'fontSize')
set(h,'fontSize',14)
xlabel('t','fontSize',14);
ylabel('\theta_2','fontSize',14);
xlim(P2, [0 10]);%trying to specify xlim
Don't juse gca at all here; use the handles to the subplots exclusively.
It doesn't make any sense from just looking at the code that the range for the x axis is any different presuming the two t vectors are really the same t at the time the plot was created.
But, without the data it's not possible to prove, but cleaning it up and redoing would be the first step--
figure
P1 = subplot(2,1,1);
plot(t,v(1,:),'linewidth',2)
xlabel('t','fontSize',14);
ylabel('\theta_1','fontSize',14);
P2 = subplot(2,1,2);
plot(t,v(2,:),'r','linewidth',2)
xlabel('t','fontSize',14);
ylabel('\theta_2','fontSize',14);
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!