1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of suptitle</title> |
---|
6 | <meta name="keywords" content="suptitle"> |
---|
7 | <meta name="description" content="SUPTITLE -Puts a title above all subplots."> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../../index.html">Home</a> > <a href="#">applications</a> > <a href="index.html">common</a> > suptitle.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for applications/common <img alt=">" border="0" src="../../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>suptitle |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
24 | <div class="box"><strong>SUPTITLE -Puts a title above all subplots.</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function hout=suptitle(str) </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment">SUPTITLE -Puts a title above all subplots. |
---|
31 | suptitle('text') adds text to the top of the figure |
---|
32 | above all subplots (a "super title"). Use this function |
---|
33 | after all subplot commands.</pre></div> |
---|
34 | |
---|
35 | <!-- crossreference --> |
---|
36 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
37 | This function calls: |
---|
38 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
39 | </ul> |
---|
40 | This function is called by: |
---|
41 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
42 | </ul> |
---|
43 | <!-- crossreference --> |
---|
44 | |
---|
45 | |
---|
46 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
47 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function hout=suptitle(str)</a> |
---|
48 | 0002 <span class="comment">%SUPTITLE -Puts a title above all subplots.</span> |
---|
49 | 0003 <span class="comment">% suptitle('text') adds text to the top of the figure</span> |
---|
50 | 0004 <span class="comment">% above all subplots (a "super title"). Use this function</span> |
---|
51 | 0005 <span class="comment">% after all subplot commands.</span> |
---|
52 | 0006 |
---|
53 | 0007 <span class="comment">% Drea Thomas 6/15/95 drea@mathworks.com</span> |
---|
54 | 0008 |
---|
55 | 0009 <span class="comment">% John Cristion 12/13/00 modified</span> |
---|
56 | 0010 |
---|
57 | 0011 <span class="comment">% Warning: If the figure or axis units are non-default, this</span> |
---|
58 | 0012 <span class="comment">% will break.</span> |
---|
59 | 0013 |
---|
60 | 0014 |
---|
61 | 0015 |
---|
62 | 0016 <span class="comment">% This will disable sub- and super-scripts (JAC)</span> |
---|
63 | 0017 |
---|
64 | 0018 set(0,<span class="string">'DefaultTextInterpreter'</span>,<span class="string">'none'</span>); |
---|
65 | 0019 |
---|
66 | 0020 <span class="comment">% Parameters used to position the supertitle.</span> |
---|
67 | 0021 |
---|
68 | 0022 <span class="comment">% Amount of the figure window devoted to subplots</span> |
---|
69 | 0023 plotregion = .92; |
---|
70 | 0024 |
---|
71 | 0025 <span class="comment">% Y position of title in normalized coordinates</span> |
---|
72 | 0026 titleypos = .95; |
---|
73 | 0027 |
---|
74 | 0028 <span class="comment">% Fontsize for supertitle</span> |
---|
75 | 0029 <span class="comment">%fs = get(gcf,'defaultaxesfontsize')+4;</span> |
---|
76 | 0030 |
---|
77 | 0031 fs = get(gcf,<span class="string">'defaultaxesfontsize'</span>); |
---|
78 | 0032 |
---|
79 | 0033 <span class="comment">% Fudge factor to adjust y spacing between subplots</span> |
---|
80 | 0034 fudge=1; |
---|
81 | 0035 |
---|
82 | 0036 haold = gca; |
---|
83 | 0037 figunits = get(gcf,<span class="string">'units'</span>); |
---|
84 | 0038 |
---|
85 | 0039 <span class="comment">% Get the (approximate) difference between full height (plot + title</span> |
---|
86 | 0040 <span class="comment">% + xlabel) and bounding rectangle.</span> |
---|
87 | 0041 |
---|
88 | 0042 <span class="keyword">if</span> (~strcmp(figunits,<span class="string">'pixels'</span>)), |
---|
89 | 0043 set(gcf,<span class="string">'units'</span>,<span class="string">'pixels'</span>); |
---|
90 | 0044 pos = get(gcf,<span class="string">'position'</span>); |
---|
91 | 0045 set(gcf,<span class="string">'units'</span>,figunits); |
---|
92 | 0046 <span class="keyword">else</span>, |
---|
93 | 0047 pos = get(gcf,<span class="string">'position'</span>); |
---|
94 | 0048 <span class="keyword">end</span> |
---|
95 | 0049 ff = (fs-4)*1.27*5/pos(4)*fudge; |
---|
96 | 0050 |
---|
97 | 0051 <span class="comment">% The 5 here reflects about 3 characters of height below</span> |
---|
98 | 0052 <span class="comment">% an axis and 2 above. 1.27 is pixels per point.</span> |
---|
99 | 0053 |
---|
100 | 0054 <span class="comment">% Determine the bounding rectange for all the plots</span> |
---|
101 | 0055 |
---|
102 | 0056 <span class="comment">% h = findobj('Type','axes');</span> |
---|
103 | 0057 |
---|
104 | 0058 <span class="comment">% findobj is a 4.2 thing.. if you don't have 4.2 comment out</span> |
---|
105 | 0059 <span class="comment">% the next line and uncomment the following block.</span> |
---|
106 | 0060 |
---|
107 | 0061 h = findobj(gcf,<span class="string">'Type'</span>,<span class="string">'axes'</span>); <span class="comment">% Change suggested by Stacy J. Hills</span> |
---|
108 | 0062 |
---|
109 | 0063 <span class="comment">% If you don't have 4.2, use this code instead</span> |
---|
110 | 0064 <span class="comment">%ch = get(gcf,'children');</span> |
---|
111 | 0065 <span class="comment">%h=[];</span> |
---|
112 | 0066 <span class="comment">%for i=1:length(ch),</span> |
---|
113 | 0067 <span class="comment">% if strcmp(get(ch(i),'type'),'axes'),</span> |
---|
114 | 0068 <span class="comment">% h=[h,ch(i)];</span> |
---|
115 | 0069 <span class="comment">% end</span> |
---|
116 | 0070 <span class="comment">%end</span> |
---|
117 | 0071 |
---|
118 | 0072 |
---|
119 | 0073 |
---|
120 | 0074 |
---|
121 | 0075 max_y=0; |
---|
122 | 0076 min_y=1; |
---|
123 | 0077 |
---|
124 | 0078 oldtitle =0; |
---|
125 | 0079 <span class="keyword">for</span> i=1:length(h), |
---|
126 | 0080 <span class="keyword">if</span> (~strcmp(get(h(i),<span class="string">'Tag'</span>),<span class="string">'suptitle'</span>)), |
---|
127 | 0081 pos=get(h(i),<span class="string">'pos'</span>); |
---|
128 | 0082 <span class="keyword">if</span> (pos(2) < min_y), min_y=pos(2)-ff/5*3;<span class="keyword">end</span>; |
---|
129 | 0083 <span class="keyword">if</span> (pos(4)+pos(2) > max_y), max_y=pos(4)+pos(2)+ff/5*2;<span class="keyword">end</span>; |
---|
130 | 0084 <span class="keyword">else</span>, |
---|
131 | 0085 oldtitle = h(i); |
---|
132 | 0086 <span class="keyword">end</span> |
---|
133 | 0087 <span class="keyword">end</span> |
---|
134 | 0088 |
---|
135 | 0089 <span class="keyword">if</span> max_y > plotregion, |
---|
136 | 0090 scale = (plotregion-min_y)/(max_y-min_y); |
---|
137 | 0091 <span class="keyword">for</span> i=1:length(h), |
---|
138 | 0092 pos = get(h(i),<span class="string">'position'</span>); |
---|
139 | 0093 pos(2) = (pos(2)-min_y)*scale+min_y; |
---|
140 | 0094 pos(4) = pos(4)*scale-(1-scale)*ff/5*3; |
---|
141 | 0095 set(h(i),<span class="string">'position'</span>,pos); |
---|
142 | 0096 <span class="keyword">end</span> |
---|
143 | 0097 <span class="keyword">end</span> |
---|
144 | 0098 |
---|
145 | 0099 np = get(gcf,<span class="string">'nextplot'</span>); |
---|
146 | 0100 set(gcf,<span class="string">'nextplot'</span>,<span class="string">'add'</span>); |
---|
147 | 0101 <span class="keyword">if</span> (oldtitle), |
---|
148 | 0102 delete(oldtitle); |
---|
149 | 0103 <span class="keyword">end</span> |
---|
150 | 0104 ha=axes(<span class="string">'pos'</span>,[0 1 1 1],<span class="string">'visible'</span>,<span class="string">'off'</span>,<span class="string">'Tag'</span>,<span class="string">'suptitle'</span>); |
---|
151 | 0105 ht=text(.5,titleypos-1,str);set(ht,<span class="string">'horizontalalignment'</span>,<span class="string">'center'</span>,<span class="string">'fontsize'</span>,fs); |
---|
152 | 0106 set(gcf,<span class="string">'nextplot'</span>,np); |
---|
153 | 0107 axes(haold); |
---|
154 | 0108 <span class="keyword">if</span> nargout, |
---|
155 | 0109 hout=ht; |
---|
156 | 0110 <span class="keyword">end</span></pre></div> |
---|
157 | <hr><address>Generated on Mon 21-May-2007 15:32:41 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
158 | </body> |
---|
159 | </html> |
---|