4.16667

4.2 | 13 ratings Rate this file 69 Downloads (last 30 days) File Size: 5.99 KB File ID: #9694

An improved subplot function

by

 

19 Jan 2006 (Updated )

An improved subplot function

| Watch this File

File Information
Description

Allows to control the distance between subplots, add labels on rows/columns only and more.
% simple example:
subplot1(2,3);
subplot1(1); plot(rand(10,1));
subplot1(2); plot(rand(10,1));
...

Acknowledgements

This file inspired Subtightplot.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (16)
25 Jun 2012 andrew joros

Great function! Thanks!

QUESTION: Is there a way to force the size of the subplot box to be perfectly square rather than a rectangle? And how to I force the axes to be all the same lengths . (i.e, X-axis is 0 to 25 and Y-axis is 0 to 25 for all subplots) ?? Thanks again!

05 Mar 2012 Aditya

Great function!

However, like Hakon, I wanted to be able to use it on the merged plots. Also, I wanted to use the standard Matlab functions as much as possible to draw the plot before applying the resize.

So I wrote a little function:
http://www.mathworks.in/matlabcentral/fileexchange/35464-spaceplots

Maybe that will help.

03 May 2011 Hakon

Very helpful, thank you! This should be standard in matlab, the gap between subplots is such a waste of space.

One thing missing from this function is the ability to merge two subplot areas into a larger plot area for some charts, e.g. subplot(3,2,[1 3]) will make the top left subplot occupy spot 1 and 3 (and so be double size vertically). Can this be added to subplot1 somehow?

17 Nov 2010 trevor

Great Subplot function.

i had similar problems as Dave Van Tol above, with subplot1 giving error messages along the lines of:
??? Error using ==> set
uimenu handle passed to 'CurrentAxes' property - valid axes handle required

Error in ==> subplot1 at 138
set(gcf,'CurrentAxes',H(M));

His suggested fix worked perfectly (include in update?)

Many thanks!

12 Nov 2010 Evgeny  
07 May 2010 ueih neyugn  
13 Jun 2008 No Body

This is exactly what I needed, thanks!

21 May 2008 Ben Kang

It's helpful. But it can not work well with mesh. For example,

subplot1(2, 2);
subplot1(1), imagesc(saliency), axis xy;
subplot1(2), mesh(saliency),

The function imagesc runs well. But mesh display the X-Y plane projection instead of the 3-D view as usual.

Do you have a solution for this?

Thanks!

13 Apr 2008 D F

Thanks for the file.

Is it possible to create square subplots and still control the gap between plots? In the example below, how would one eliminate the excess space between columns?

%The goal is a 2*2 plot, in which each plot %is square and has equal length axes. %However, the figure has too much horizontal %space between columns.

subplot1(2,2,'Gap',[0.003 0.003])
plot_num = 0;
for i=1:2
for j=1:2
plot_num = plot_num + 1;
subplot1(plot_num);
plot(randn(100,1),randn(100,1),'k.')
axis([-3 3 -3 3])
axis square
end
end

15 Feb 2008 Dave Van Tol

It helped me solve my problem.

One thing I have changed... subplot1 assumes that all of the children of the current figure are axes. That assumption is not always true. For example, turning on the data cursor (datacursormode on) adds a handle to the current figure. If that figure is reused, subplot1 mistakes that extra handle as an axes and the result is an error.

The root of the problem seems to be lines 111 and 112, which say:

H = get(gcf,'Children');
Ptot = length(H);

It would be good to eliminate the handles from H that are not axes. I have replaced line 112 with:

Ptot = sum(strcmp(get(H,'type'),'axes'));

That fixes the problem.

05 Oct 2007 Fuu-Ming Kai

It's very good. Save me a lot of time. It will be great if there is more information to talk about how to use it. For example, I just figured out, if you want to add a label in different subplot (e.g. 1st plot), you need to type >> subplot1(1); xlabel('time'). Overall, I like it a lot. Thanks!

15 Feb 2007 Dagang Wang

It's good. I like it

17 Nov 2006 Spencer Chen

I thought I can add labels to subplot rows and coloumns.... can someone show me how?

17 Nov 2006 Spencer Chen

I like the control over the gap size. But this creates axes where I do not intend to place any plots at all. Have to delete those one by one... and in reverse order, so that I do not stuff the internal structure subplot1 has set up.

24 Jan 2006 John D'Errico

Note: If you do as Martin suggests (not a bad idea) only create the array of handles when nargout>0. This way when subplot is called wth no outputs, there will be no spewing of the unwanted handles array to the command line.

24 Jan 2006 Martin Lechner

Very good if you add the axes handles as output parameter.
You must change only the following lines:

1: function hAxes = subplot1(M,N,varargin);
139: hAxes = H(M);
172: hAxes(Row,Col) = axes('position',[Xstart,Ystart,Xbox,Ybox]);

Contact us