Subplot disappears on reposition

1 次查看(过去 30 天)
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.

采纳的回答

per isakson
per isakson 2013-7-19
编辑:per isakson 2013-7-19
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 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by