Code covered by the BSD License  

Highlights from
Controllable tight subplot

4.0

4.0 | 3 ratings Rate this file 133 Downloads (last 30 days) File Size: 486 KB File ID: #30884
image thumbnail

Controllable tight subplot

by

 

29 Mar 2011 (Updated )

Subplot wrapper, allowing better figure utilization, by tighter axes.

| Watch this File

File Information
Description

Allows fully utilizing the figure surface by defining margins, by wrapping the existing subplot function. Unfortunately the original subplots function spends lavishly the figure area , without allowing the user to control it in a convenient manner. In addition to subplot functionality (fully supported) the user can define margins, which result in larger axis presented in the figure. Default margins are 1% of figure area.
Thanks goes to a colleague- Adi N., who both urged me to write this function down, and assisted in writing it.
Hope you will find this one useful.

Update:
Some subplot functionality s now supported. However, I must mention this looks quiet buggy to me. Check this out:
 figure;
 subplot(1,2,1);
 plot(rand(1,20));
 subplot(1,2,1,'Position',[0.1,0.1,0.3,0.3]); % 'Position' is ignored!!!

Acknowledgements

This file inspired Subtightplot.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
27 Dec 2012 Felipe G. Nievinski

I love that it can replace the built-in subplot with minor modification in the caller script. I wish it could handle margins in addition to gaps though.

22 Dec 2011 Nikolay S.

Hello AMVR.
First of all, there is no need for repeating your message. It is perfectly clear when written once.

To the point- your script's issue can be solved by setting the figure size to the desired dimentions. Either repalce the figure command with : "figure('Position', [0,0,240,291*2]);",
or add :
"set(gcf, 'Position',[0,0,240,291*2])";
after your script.
I trust you will know where do the figure "position" parameters come from...
Regarding "subplot_tight" functionality as I see it. subplot_tight gola is to devide the figure to subplots spaced by margins specified by the user. Unfortunately, in case of image data (and some other cases) I have no way of knowing in advance what are the appropriate figure dimensions (as plotting commands follow subplot_tight). This will work differently with plot commands btw.

To see for yourself run the following command "subplot_tight(1,2,1, [0,0])" and verify that the axis "subplot_tight" generates have no (0) margins. The following "imshow" command in your script, actually places into the axis a plot with smaller dimensions, which results in margins you're so unhappy about.
So at this point setting appropriate figure size is under users responsibility. Actually it is not too hard to deal with, but unfortunately I found no way to do it inside subplot_tight scope.
Hope I've unswered your question.
Best regards.

21 Dec 2011 AMVR

Could you comment on why the script below using your code does not work ? MATLAB displays extra vertical space even though I asked for empty margins:

figure;
I = imread('pout.tif');
margins = [0 0];
subplot_tight(1,2,1, margins)
imshow(I');
subplot_tight(1,2,2, margins)
imshow(I');

21 Dec 2011 AMVR

Could you comment why the script below using your code does not work ? MATLAB displays extra vertical space even though I asked for empty margins:

figure;
I = imread('pout.tif');
margins = [0 0];
subplot_tight(1,2,1, margins)
imshow(I');
subplot_tight(1,2,2, margins)
imshow(I');

16 Apr 2011 Alan B

Yes, that's right. This is how subplot.m works - it creates new axes on a figure, but it also simply sets existing axes as current, if the same mnp value is given. I'm not sure how subplot accomplishes this, but using tags is a quick solution that will work most of the time.

12 Apr 2011 Nikolay S.

Hi Alan.
Thank you for your comment and rating. Could you explain in more detail the feature you want to be added? Assuming subplot is called with [m,n,p] do you want to take care of the case where subplot_tight is called with same []m,n,p] ? You want only the axis CData to be replaced, instead deleting current axis and creating a new one instead? Please elaborate.
Regards.

12 Apr 2011 Alan B

Useful, concise function. It would be more useful if calling repeatedly with the same parameters did not destroy the previously-created axes (this is how subplot behaves). I did this by tagging the subplot_tight axes, then checking if an axes with that tag already exists on the current figure.

30 Mar 2011 Egon Geerardyn  
Updates
30 Mar 2011

.png replaced by .jpg's, to reduce file size, screen-shot modified.

21 Apr 2011

A bit shorter implementation, now supporting functionality Allan has requested.

Contact us