4.33333

4.3 | 3 ratings Rate this file 43 Downloads (last 30 days) File Size: 27.2 KB File ID: #34191
image thumbnail

subplot_grid

by Joris Kampman

 

13 Dec 2011 (Updated 26 Apr 2013)

A subplot figure with a lot of fancy features

| Watch this File

File Information
Description

SUBPLOT_GRID is a class with which a set of subplots can be created in a space-optimal way. In addition, a figure title and subtitle may be added, as well as specific row and column titles.

Subplots may be merged like normal, and can be zoomed in via a simple mouse click or method. Zooming in more than 1 subplot is also possible by linking the zooming action of multiple axes.

The INTERAXES function provides the possibility to show the clicked on data point in an axes, and to shows its values in the title.

The methods LEGEND and COLORBAR ensure a correct handling on zooming and resizing.

Available methods:
FIGTITLE - Adds a figure title
SUBFIGTITLE - Adds a subtitle
COLTITLES - Adds column titles
ROWTITLES - Adds row titles
SET_GCA - set a subplot as current axes
DISABLE_SUBPLOTZOOM - Disable subplot zoom
ENABLE_SUBPLOTZOOM - Enable subplot zoom
HIDE_AXES - Hides axes
SHOW_AXES - Shows a hidden axes
ENABLE_INTERAXES - Enable the interaxes functionality in which the axes data becomes clickable
DISABLE_INTERAXES - Disables the interaxes functionality
OVERWRITE_INTERAXES_SELECTION_MODS - Overwrites the default selection modifications
HIDE_EMPTY_AXES - Hides all empty axes
LEGEND - creates a predefined legend
RELOCATE_LEGEND - re-locates the legend
REMOVE_LEGEND - Removes legend(s)
X_SYNC_AXES - Sync x axes to master axes
COLORBAR - creates a colorbar to an axes

run 'subplot_grid' for a demo.

The syntax of every method can be found by 'help subplot_grid.<method>'

Acknowledgements

This file inspired Subtightplot.

MATLAB release MATLAB 7.13 (R2011b)
Tags for This File  
Everyone's Tags
interactive axes, legend, merge, oop, subplot, zoom
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
14 Feb 2013 Dan K

Joris,

Here's a thought for you: Have you considered setting it up so that the grid can live inside some other parent besides its own figure? I'm setting up a GUI, and I'd like to consider putting a grid inside a uipanel.... Thoughts?

25 May 2012 Dan K

Sorry about that last. Hit return by mistake. Joris, I've run into an issue using subplot_grid, which may be fairly unique, but I thought I would mention it. In order to save figures and be able to change them later, I'm using setappdata to copy the subplot_grid object into the figure's appdata. However, this has an interesting consequence: After I've cleared the figure, the object which is saved in the application data is still listening for callbacks, such as resize, and throwing an error:

Cell contents reference from a non-cell array object.
Error in cell2mat (line 43)
cellclass = class(c{1});
Error in subplot_grid/reset_handles (line 3279)
positions = cell2mat(get(haxs(:),'OuterPosition'));
Error in subplot_grid/subplot_resize_fcn (line 2153)
this.reset_handles;
Error in subplot_grid>@(src,evt)this.subplot_resize_fcn (line 429)
set(this.hfig,'ResizeFcn',@(src,evt)this.subplot_resize_fcn);

I'm looking for a place where I can test to check if the object is still referring to a valid grid, and abort. An alternative would be to find a way to clear out the appdata on a clf. If you have any suggestions, I'd appreciate it.

Thanks,
Dan

25 Apr 2012 Karl

The demo really shows what this can do. However, it doesn't show how to do it. I would probably increase my rating to a 5star if there were examples to go along with the function.

16 Apr 2012 Dan K

Joris,
Again, I applaud your good work. This has rapidly become one of my favorite FEX functions.
Another items to think about adding when you get around to it:
I would find it useful to be able to create a shared xlabel (much like the coltitle method) only at the bottom of the figure.

02 Mar 2012 Joris Kampman

I've uploaded a newer version (internal version 4.4). I've been able to fix the bugs found, except the problem with PLOTYY which uses two overlaying transparent axes. This is quite horrible for the script, so I really have to think about this, and for sure this will have a BIG impact on the function.

The addition of a COLORBAR was done and a method SET_PADDING to control the padding between axes.

However, a combination of all possible actions was not done, so please keep me informed on found errors/bugs

01 Mar 2012 Dan K

Joris,
I've come across another item that could use a little work. If you clear a figure that used to have a grid, it fails anytime on account of the resize function (see below). I think this could be resolved with an appropriate destructor method.

Again, thank you for your great work.
Dan

Error using handle.handle/get
Invalid or deleted object.

Error in subplot_grid/resize_wo_legend (line 3129)
units = get(this.hax(ir,ic),'Units');

Error in subplot_grid/subplot_resize_fcn (line 1986)
this.resize_wo_legend;

Error in subplot_grid>@(varargin)this.subplot_resize_fcn(varargin{:}) (line 399)
set(this.hfig,'ResizeFcn',@this.subplot_resize_fcn);

Error using drawnow
Error while evaluating figure ResizeFcn

23 Feb 2012 Fernando  
22 Feb 2012 Fernando

Colorbar position are not respected when resizing and their labels appear on top of next subplot ticklabels or outside the margins of the figure

18 Feb 2012 Joris Kampman

Thanks for the nice comment. Regarding your points:
1. I've thought about an output for set_gca, however after this method, you can use 'gca' if necessary, or just add titles and such. For instance, I always use: set_gca(x,y);title(...);set(gca,'',''),...
If you just need any handle, you can use the property 'hax', which contains all axes. for instance <class>.hax(2,3) outputs the axes handle for the subplot in row 2, column 3.

2. I'll add a property to control the whitespace; no problem.

3. Oef, I've just seen the shit occurring when using plotyy (which obviously, I myself rarely use). I'll have to investigate a bit what to do about this.

Please keep me informed on any other bugs/improvements

14 Feb 2012 Dan K

Very nice work... A couple of (maybe) suggestions. (Maybe, because they might already be implemented, and I just didn't find them). Create an output for the set_gca method which is the handle of the axes you just selected (useful for titles,TickValues, etc.) Also, allow some control over the amount of whitespace between axes. It also really seems to dislike plotyy. But all told, it's one of the better subplot functions I've seen.

Updates
25 Jan 2012

some bugfixes on legend placements, and the correct working with zooming in and out.

02 Mar 2012

1: Matched the legend style to MATLAB
2: Bugfix in the legend placement
3: Added correct handling of axes deletion.
4: Added COLORBAR method.
5: Added SET_PADDING which allows control over the amount of whitespace between axes

26 Apr 2013

-Bugfixes
-speed improvement (thanks to Dan Kominsky)
-added method COLORBAR
-added possibility to link axes on zooming in

Contact us