Subplot not displaying when specifying position

42 views (last 30 days)
I have a figure that has 3 subplots and I was attempting to make the first two subplots larger. I've done this before in another figure and it worked fine but this one is giving me problems.
When I have a line with the subplot function with no position specification the subplot shows up, but is not the size I want. If I use a position specification the subplot does not show up at all. Below is my code and the two figures that show when position is or is not specified.
warning('off');
subplot(3,1,2); %displays subplot of wrong size
%subplot(3,1,2,'Position',[0.13,0.303867403314917,0.775,0.321500243743906]);
plot(BI.bint,[0.*[1:1:74] r1(index,:)],'-b')
hold on
ranging=1.5.*max(abs(r1(index,14:end)));
set(gca,'Ylim',[-ranging, ranging])
ylabel 'residual'
hold off
This is the figure that shows up when I do not specify position, but the second subplot is the incorrect size.
Then when I use the specified position, as shown below, I get the figure shown below.
warning('off');
%subplot(3,1,2); %displays subplot of wrong size
subplot(3,1,2,'Position',[0.13,0.303867403314917,0.775,0.321500243743906]); %second subplot doesn't show.
plot(BI.bint,[0.*[1:1:74] r1(index,:)],'-b')
hold on
ranging=1.5.*max(abs(r1(index,14:end)));
set(gca,'Ylim',[-ranging, ranging])
ylabel 'residual'
hold off
Any ideas?
  2 Comments
dpb
dpb on 2 Apr 2020
Yeah, your requested position parameters are probably outside the range so one overlaps the other, in which case according to the documentation,
"subplot('Position',pos) creates axes in the custom position specified by pos. Use this option to position a subplot that does not align with grid positions. Specify pos as a four-element vector of the form [left bottom width height]. If the new axes overlap existing axes, then the new axes replace the existing axes."
Create the standard subplot(3,1,i) and then fudge the position of the resulting axis.
Mohammad Sami
Mohammad Sami on 2 Apr 2020
If you are using >= 2019b version of matlab, you can also try the tiledlayout function.

Sign in to comment.

Answers (1)

Garrett Marshall
Garrett Marshall on 25 Sep 2020
The same thing happened to me, and dpb is right that the image axes were overlapping. I simply gave the subplots more buckets and my image popped up. You could try changing to subplot(4,1,i) and putting your 3rd plot in subplot(4,1,4). Keep all of your current positions though.
This is what worked for me. I hope it helps!

Products

Community Treasure Hunt

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

Start Hunting!