MATLAB Answers


Five plots arranged like on dice?

Asked by Jakub
on 21 Aug 2013
Accepted Answer by dpb

How can I arrange five plots in one figure so the plots would be on same positions like points on a dice? I dont want subplot (3,3,...) because of too much empty space. Thanks


on 21 Aug 2013

Hmmmm....that now looks completely_different than when I carefully formatted it in the preview pane... :( Including munging on the values. I've no klew how that happend--I'll see if can clean it up.

ADDENDUM--ok the automagic wordwrap struck again -- the formatting all went away simply because I didn't turn the arrangement "figure" into a code block--yet another reason that TMW really, really needs to make that the default instead--having to physically format code in a coding forum just makes no sense at of the reasons I'm scaling back drastically--this sort of what should be needless fixup just takes too much time/effort. :(

ADDENDUM 2: I moved it to Answer since did expand into working code and deleted the comment.


No products are associated with this question.

2 Answers

Answer by dpb
on 21 Aug 2013
Edited by dpb
on 21 Aug 2013
 Accepted answer


a) use subplot(2,3) and rearrange the two middle (make one invisible and move position of the second), or

b) draw them all individually where you want them.

Example for a) (which is what I think I'd do...)

for i=1:6, h(i)=subplot(2,3,i); end  % make the six, save handles
delete(h(2))                         % wipe out the middle top one
p=get(h(5),'position');              % position of middle bottom
pt=get(h(1),'position');             % position of a upper
p(2)=(pt(2)+p(2))/2;                 % center of bottom for the two rows
set(h(5),'position',p)               % move the middle to there...
h(2)=[];                             % remove the nonexistent handle

Just remember that they're numbered sequentially now in position as

1   3          1   2
  5       -->    4  
4   6          3   5

You can always rearrange the handles in the h vector--swapping h(3) and h(4) would put them from L to R, T to B which probably as easy an ordering as there is, consistent w/ subplot itself.


Answer by the cyclist
on 21 Aug 2013
Edited by the cyclist
on 21 Aug 2013

Here is a simple, general example of how to position two sets of axes in one figure.

ax1 = axes;
ax2 = axes;
set(ax1,'Position',[0.5 0.5 0.35 0.25])
set(ax2,'Position',[0.1 0.1 0.25 0.35])
h1 = plot(ax1,rand(3,1),rand(3,1),'.');
h2 = plot(ax2,rand(3,1));

You can also adjust the size of the figure window itself with

set(gcf,'Position',<coordinates here>)



Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today