|
a |
|
b/combinedDeepLearningActiveContour/functions/subplot_tight.m |
|
|
1 |
function h=subplot_tight(m,n,p,margins,varargin) |
|
|
2 |
%function subplot_tight(m,n,p,margins,varargin) |
|
|
3 |
% |
|
|
4 |
% Functional purpose: A wrapper function for Matlab function subplot. Adds the ability to define the margins between |
|
|
5 |
% neighbouring subplots. Unfotrtunately Matlab subplot function lacks this functionality, and the margins between |
|
|
6 |
% subplots can reach 40% of figure area, which is pretty lavish. |
|
|
7 |
% |
|
|
8 |
% Input arguments (defaults exist): |
|
|
9 |
% margins- two elements vector [vertical,horizontal] defining the margins between neighbouring axes. Default value |
|
|
10 |
% is 0.01. Note this vale will cause titles legends and labels to collide with the subplots, while presenting |
|
|
11 |
% relatively large axis. |
|
|
12 |
% |
|
|
13 |
% Output arguments: same as subplot- none, or axes handle according to function call. |
|
|
14 |
% |
|
|
15 |
% Issues & Comments: Note that if additional elements are used in order to be passed to subplot, margins parameter must |
|
|
16 |
% be defined. For default margins value use empty element- []. |
|
|
17 |
% |
|
|
18 |
% Author and Date: Nikolay S. 29/03/2011. |
|
|
19 |
% Last update: Nikolay S. 21/04/2011 (accourding to Alan B comment). |
|
|
20 |
% |
|
|
21 |
% Usage example: h=subplot_tight((2,3,1:2,[0.5,0.2]) |
|
|
22 |
|
|
|
23 |
if (nargin<4) || isempty(margins) |
|
|
24 |
margins=[0.01,0.01]; % default margins value- 1% of figure |
|
|
25 |
end |
|
|
26 |
|
|
|
27 |
if length(margins)==1 |
|
|
28 |
margins(2)=margins; |
|
|
29 |
end |
|
|
30 |
|
|
|
31 |
%note n and m are switched as Matlab indexing is column-wise, while subplot indexing is row-wise :( |
|
|
32 |
[subplot_col,subplot_row]=ind2sub([n,m],p); |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
height=(1-(m+1)*margins(1))/m; % single subplot height |
|
|
36 |
width=(1-(n+1)*margins(2))/n; % single subplot width |
|
|
37 |
|
|
|
38 |
% note subplot suppors vector p inputs- so a merged subplot of higher dimentions will be created |
|
|
39 |
subplot_cols=1+max(subplot_col)-min(subplot_col); % number of column elements in merged subplot |
|
|
40 |
subplot_rows=1+max(subplot_row)-min(subplot_row); % number of row elements in merged subplot |
|
|
41 |
|
|
|
42 |
merged_height=subplot_rows*( height+margins(1) )- margins(1); % merged subplot height |
|
|
43 |
merged_width= subplot_cols*( width +margins(2) )- margins(2); % merged subplot width |
|
|
44 |
|
|
|
45 |
merged_bottom=(m-max(subplot_row))*(height+margins(1)) +margins(1); % merged subplot bottom position |
|
|
46 |
merged_left=min(subplot_col)*(width+margins(2))-width; % merged subplot left position |
|
|
47 |
pos_vec=[merged_left merged_bottom merged_width merged_height]; |
|
|
48 |
|
|
|
49 |
% h_subplot=subplot(m,n,p,varargin{:},'Position',pos_vec); |
|
|
50 |
% Above line doesn't work as subplot tends to ignore 'position' when same mnp is utilized |
|
|
51 |
h_subplot=subplot('Position',pos_vec,varargin{:}); |
|
|
52 |
|
|
|
53 |
if nargout~=0 |
|
|
54 |
h=h_subplot; |
|
|
55 |
end |