Hello , I have an issue with getting everything to show on my figure correctly. I made four subplots but for some reason my 4th subplot is not showing and also the legend, text and title is not showing correctly either

24 次查看(过去 30 天)
Hello ,
I have an issue with getting everything to show on my figure correctly. I made four subplots but for some reason my 4th subplot is not showing and also the legend, text and title is not showing correctly either
please help
Here's my code
%% Plot
figure;
plot(t,x11,'-*'),hold on;
plot(t,x(:,1),'-')
title('x1 vs Non-linear')
legend({'x1','Non-linear'},'Location','northeast')
txt = {'eq point [0.5,0.5]','initial point[0.51,0.51]'};
text(.4,10,txt)
subplot(2,2,1)
plot(t,x12,'-*'),hold on;
plot(t,x(:,2),'-')
title('x2 vs Non-linear')
legend({'x2','Non-linear'},'Location','northeast')
txt = {'eq point [0.5,0.5]','initial point[0.51,0.51]'};
text(.4,10,txt)
subplot(2,2,2)
plot(t,x13,'-*'),hold on;
plot(t,x1(:,1),'-')
title('x1 vs Non-linear')
legend({'x1','Non-linear'},'Location','northeast')
txt = {'eq point [0.5,0.5]','initial point[1,1]'};
text(.4,10,txt)
subplot(2,2,3)
plot(t,x14,'-*'),hold on;
plot(t,x1(:,2),'-');
title('x2 vs Non-linear')
legend({'x2','Non-linear'},'Location','northeast')
txt = {'eq point [0.5,0.5]','initial point[1,1]'};
text(.4,10,txt)
subplot(2,2,4)

采纳的回答

dpb
dpb 2019-11-12
编辑:dpb 2019-11-12
You plot() BEFORE you create the subplot; so the first plot is killed/destroyed after it is made when the subplot(2,2,1) call is made--then what is intended to be the second plot is plotted into that subplot axes. Same thing for the subsequent -- each is plotted into the subplot axes creathed ahead of it. There's no plot() command after the last suplot() axes is created; hence it's empty.
MORAL: Create the subplot() axis FIRST, then plot into it.
figure;
subplot(2,2,1)
plot(t,x11,'-*'),hold on;
plot(t,x(:,1),'-')
title('x1 vs Non-linear')
legend({'x1','Non-linear'},'Location','northeast')
txt = {'eq point [0.5,0.5]','initial point[0.51,0.51]'};
text(.4,10,txt)
subplot(2,2,2)
plot(t,x12,'-*'),hold on;
plot(t,x(:,2),'-')
...
  2 个评论
Mohamed AL Sager
Mohamed AL Sager 2019-11-12
That helped, however the text is not showing in some of the graphs still
%% Plot
figure;
subplot(2,2,1)
plot(t,x11,'-*'),hold on;
plot(t,x(:,1),'-')
title('x1 vs Non-linear')
legend({'x1','Non-linear'},'Location','northeast')
txt = {'eq point [0.5,0.5]','initial point[0.51,0.51]'};
text(.4,10,txt)
subplot(2,2,2)
plot(t,x12,'-*'),hold on;
plot(t,x(:,2),'-')
title('x2 vs Non-linear')
legend({'x2','Non-linear'},'Location','northeast')
txt = {'eq point [0.5,0.5]','initial point[0.51,0.51]'};
text(.4,10,txt)
subplot(2,2,3)
plot(t,x13,'-*'),hold on;
plot(t,x1(:,1),'-')
title('x1 vs Non-linear')
legend({'x1','Non-linear'},'Location','northeast')
txt = {'eq point [0.5,0.5]','initial point[1,1]'};
text(.4,10,txt)
subplot(2,2,4)
plot(t,x14,'-*'),hold on;
plot(t,x1(:,2),'-');
title('x2 vs Non-linear')
legend({'x2','Non-linear'},'Location','northeast')
txt = {'eq point [0.5,0.5]','initial point[1,1]'};
text(.4,10,txt)
Capture.PNG
dpb
dpb 2019-11-12
编辑:dpb 2019-11-12
Use the CODE button to format the code to be legible.
The cut 'n paste ended up with the first subplot() call in front of the figure command -- reordered above.
Just go through logically and in sequence and get what you want on each plot in the sequence after beginning each supbplot().
It's wise to save the axes handles created so you can refer to the desired axis later on if want to add or modify something on one.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by