Subplot disappears on reposition
3 views (last 30 days)
Show older comments
I have the following function that is supposed to create subplots that are tightly spaced within a row, and distributed with spacing in each column. It also lets you set buffer sizes for the edges:
function fill_graph()
for x=1:3
for y=1:3
ax = subplot(3,3,(x-1)*3+y);
left_buffer = .05;
right_buffer = .025;
x_pos = left_buffer+(x-1)*(1/3*(1-left_buffer-right_buffer));
width = 1/3*(1-left_buffer-right_buffer);
bottom_buffer = .1;
top_buffer = .05;
spacing=.07;
height = (1/3)*(1-2*spacing-top_buffer-bottom_buffer);
y_pos = bottom_buffer+(y-1)*(spacing+height);
set(ax,'position',[x_pos,y_pos,width,height])
if x>1
set(gca,'yTickLabel','');
ylabel('');
end
if y>1 || x~=2
xlabel('')
end
end
end
When I run the function, the bottom row of plots and the leftmost plot on the middle row all disappear.
I'm aware this probably has something to do with the fact that subplots will disappear when they overlap with one another, but regardless of how far apart I set the spacing, I can't get the bottom row to appear (the only way I've found is setting the bottom buffer above .34, which only works some of the time). I've tried switching 'position' to 'outerposition', which should make it so that none of them overlap, but that doesn't seem to work either.
Is there a workaround for this?
Thanks.
0 Comments
Accepted Answer
per isakson
on 19 Jul 2013
Edited: per isakson
on 19 Jul 2013
I think something is wrong in ax = subplot(3,3,(x-1)*3+y);. Maybe a row-column mixup? In your code, axes are overwritten by succeeding axes and then repositioned.
See
and search FEX for
0 Comments
More Answers (0)
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!