JISUBPLOT + NEXTPLOT: enhanced replacement for subplot

Automatically create complex subplot layouts
1.6K Downloads
Updated 31 Aug 2006

View License

OVERVIEW: Enhanced replacement for SUBPLOT

Problem:
Multi-axis plotting (using SUBPLOT) is great and essential, but has
shortcomings. The main one is that keeping track of the axis indexes
can be tedious if you want to do anything more elaborate than plotting
in row-order. In addition, the size of all axes are the same, and
spacing is not adjustable.

Solution: JISUBPLOT + NEXTPLOT
What you might really want is to set up a grid of subplots once and
then just tell the figure when you want to move to the next plot,
letting it take care of the details for you.

That's what the pair of functions JISUBPLOT and NEXTPLOT can do.
It decouples the specification of the subplot grid (JISUBPLOT) from the
act of moving around it and creating new axes at various positions
(and sizes) within the grid (NEXTPLOT).

The key that differentiates this solution is NEXTPLOT. Using it,
you can create new axes, automatically move by row, or by column,
or arbitrarily. You can create subplots of mixed sizes. You don' t
need to concern yourself with subplot indexes or coordinates
and can concentrate on how you want the layout to appear.

NEXTPLOT is especially useful in loops where you want create an array of many plots:

jisubplot(2,4,0)
for idx = 1:8,
nextplot('newcol')
plot(something{idx})
nextplot('bycol')
plot(something_related{idx})
end

Finally, wouldn't it be nice if when you changed a figure's orientation (e.g. orient tall), it actually changed shape to reflect that? JISUBPLOT does that.

Examples:

%% the basic idea
figure
jisubplot(4,2,1) % can be used just like SUBPLOT
plot(X)
nextplot % advance to next axis
plot(something_else)
nextplot
plot(some_other_thing)

nextplot('newRow') % start a new row of axes
plot(something_new)
nextplot('byCol') % move down columns
etc...

%% jisubplot / nextplot is especially useful in loops
%% it will extend to new figures automatically
figure
jisubplot(4,4,0) %setup figure, but don't make the first axis
for idx = 1:32,
nextplot('bycol')
title(num2str(idx))
plot(data(idx,:))
end

%% a more complete usage: specify orientation, plot spacing and fontsize
%% figure window is sized appropriately for orientation
figure
jisubplot(5,3,0,'tall',[.3 .3],'fontsize',9)
nextplot
etc...

Run JISUBPLOTDEMO for executable examples of more advanced usage.

Distribution includes:

jisubplot.m -- setup figure for automated multi-pane layout
nextplot.m -- automatically advance to next pane

currentplotis.m -- test location of current axis

jisubplotdemo.m -- demonstration of usage

And the following general utility files (used by nextplot)
These are used for parameter/value argument parsing,
and may be generally of use.

isparam.m -- test for presence of a parameter
getparam.m -- get values following a parameter
strmatch_mixed.m -- strmatch that can be used on cell arrays with non-string elements
useful when parsing parameter/value lists

Cite As

John Iversen (2024). JISUBPLOT + NEXTPLOT: enhanced replacement for subplot (https://www.mathworks.com/matlabcentral/fileexchange/12103-jisubplot-nextplot-enhanced-replacement-for-subplot), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Axes Appearance in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0

Improvements to formatting of description.