I thought I had seen a function somewhere that would modify subplots so that each of the plots would have the same scale (i.e., ylim) and all of them fit nicely. Kind of like "auto" for the subplot with the highest amplitude applied to all of the subplots. Is there such a function, or option for an existing function?
Kshitij Singh answered .
2025-11-20
Once you've finished creating all the subplots (and you have the handles), you can set all of them at once by using :
set(AX_handles,'YLim',[A B])
Where AX_handles is a vector of axes handles, one for each subplot- for example:
for n=1:10 AX(n) = subplot(5,2,n) end
A and B are your lower and upper limits. Finding the overall max will vary a bit depending on how your data is structed but it shouldn't be too hard.
subplot divides the current figure into rectangular panes that are numbered rowwise. Each pane contains an axes object. Subsequent plots are output to the current pane.
h = subplot(m,n,p), or subplot(mnp) breaks the Figure window into an m-by-n matrix of small axes, selects the pth axes object for for the current plot, and returns the axis handle. The axes are counted along the top row of the Figure window, then the second row, etc. For example,
plots income on the top half of the window and outgo on the bottom half. If the CurrentAxes is nested in a uipanel, the panel is used as the parent for the subplot instead of the current figure. The new axes object becomes the current axes.
If p is a vector, it specifies an axes object having a position that covers all the subplot positions listed in p.
subplot(m,n,p,'replace') If the specified axes object already exists, delete it and create a new axes.
subplot(m,n,p,'align') positions the individual axes so that the plot boxes align, but does not prevent the labels and ticks from overlapping.
subplot(h) makes the axes object with handle h current for subsequent plotting commands.