Changing subplot x limit
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 27 Jan. 2021
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);
Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!