comparison scripts/plot/subplot.m @ 6257:44c91c5dfe1d

[project @ 2007-01-30 19:16:52 by jwe]
author jwe
date Tue, 30 Jan 2007 19:16:55 +0000
parents 830235f4984f
children 0fcce0872e02
comparison
equal deleted inserted replaced
6256:83949ae13b2c 6257:44c91c5dfe1d
57 ## @end tex 57 ## @end tex
58 ## @end iftex 58 ## @end iftex
59 ## @ifinfo 59 ## @ifinfo
60 ## @display 60 ## @display
61 ## @group 61 ## @group
62 ## @example
63 ##
62 ## +-----+-----+-----+-----+ 64 ## +-----+-----+-----+-----+
63 ## | 1 | 2 | 3 | 4 | 65 ## | 1 | 2 | 3 | 4 |
64 ## +-----+-----+-----+-----+ 66 ## +-----+-----+-----+-----+
65 ## | 5 | 6 | 7 | 8 | 67 ## | 5 | 6 | 7 | 8 |
66 ## +-----+-----+-----+-----+ 68 ## +-----+-----+-----+-----+
69 ## @end example
67 ## @end group 70 ## @end group
68 ## @end display 71 ## @end display
69 ## @end ifinfo 72 ## @end ifinfo
70 ## @seealso{plot} 73 ## @seealso{plot}
71 ## @end deftypefn 74 ## @end deftypefn
72 75
73 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> 76 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
74 ## Adapted-By: jwe 77 ## Adapted-By: jwe
75 78
76 function subplot (rows, columns, index) 79 function h = subplot (rows, columns, index)
77
78 __plot_globals__;
79
80 cf = __current_figure__;
81 80
82 if (nargin != 3 && nargin != 1) 81 if (nargin != 3 && nargin != 1)
83 print_usage (); 82 print_usage ();
84 endif 83 endif
85 84
110 109
111 if (columns < 1 || rows < 1 || index < 1) 110 if (columns < 1 || rows < 1 || index < 1)
112 error ("subplot: columns,rows,index must be be positive"); 111 error ("subplot: columns,rows,index must be be positive");
113 endif 112 endif
114 113
115 if (columns*rows == 1) 114 xsize = 1 / columns;
115 ysize = 1 / rows;
116 116
117 ## switching to single plot ? 117 yp = fix ((index-1)/columns);
118 xp = index - yp*columns - 1;
118 119
119 oneplot (); 120 xorigin = xp * xsize;
121 yorigin = (rows - yp - 1) * ysize;
120 122
121 __multiplot_xn__(cf) = 1; 123 pos = [xorigin, yorigin, xsize, ysize];
122 __multiplot_yn__(cf) = 1;
123 124
124 else 125 cf = gcf ();
125 126
126 ## doing multiplot plots 127 set (cf, "nextplot", "add");
127 128
128 if (! __multiplot_mode__(cf) 129 obj = get (cf);
129 || __multiplot_xn__(cf) != columns
130 || __multiplot_yn__(cf) != rows)
131 130
132 if (__multiplot_xn__(cf) < columns 131 found = false;
133 || __multiplot_yn__(cf) < rows) 132 for child = obj.children
134 __plot_data__{cf}{columns,rows} = []; 133 obj = get (child);
134 if (strcmp (obj.type, "axes"))
135 if (obj.outerposition == pos)
136 found = true;
137 tmp = child;
138 axes (h);
139 break;
135 endif 140 endif
141 endif
142 endfor
136 143
137 __multiplot_mode__(cf) = true; 144 if (! found)
138 __multiplot_xn__(cf) = columns; 145 tmp = axes ("outerposition", pos);
139 __multiplot_yn__(cf) = rows; 146 endif
140 __multiplot_xsize__(cf) = 1 / columns;
141 __multiplot_ysize__(cf) = 1 / rows;
142 147
143 endif 148 if (nargout > 0)
144 149 h = tmp;
145 ## get the sub plot location
146
147 yp = fix ((index-1)/columns);
148 xp = index - yp*columns - 1;
149 __multiplot_xi__(cf) = ++xp;
150 __multiplot_yi__(cf) = ++yp;
151
152 ## set the origin
153
154 xo = (xp - 1.0) * __multiplot_xsize__(cf);
155 yo = (rows - yp) * __multiplot_ysize__(cf);
156
157 endif 150 endif
158 151
159 endfunction 152 endfunction