annotate scripts/plot/subplot.m @ 1540:749b8b19733f

[project @ 1995-10-06 03:10:34 by jwe] Initial revision
author jwe
date Fri, 06 Oct 1995 03:10:34 +0000
parents
children 47bd45a30dda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1540
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
1 # Copyright (C) 1995 John W. Eaton
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
2 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
3 # This file is part of Octave.
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
4 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
5 # Octave is free software; you can redistribute it and/or modify it
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
6 # under the terms of the GNU General Public License as published by the
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
7 # Free Software Foundation; either version 2, or (at your option) any
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
8 # later version.
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
9 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
10 # Octave is distributed in the hope that it will be useful, but WITHOUT
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
13 # for more details.
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
14 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
16 # along with Octave; see the file COPYING. If not, write to the Free
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
18 # 02111-1307, USA.
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
19
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
20 function subplot (rows, columns, index)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
21
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
22 # usage: subplot (rows, columns, index)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
23 # subplot (rcn)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
24 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
25 # NOTE: this will work only with gnuplot installed with
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
26 # multiplot patch (or version 3.6 beta)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
27 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
28 # Sets gnuplot in multiplot mode and plots in location
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
29 # given by index (there are columns X rows subwindows)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
30 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
31 # Input:
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
32 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
33 # rows : number of rows in subplot grid
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
34 # columns: number of columns in subplot grid
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
35 # index : index of subplot where to make the next plot
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
36 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
37 # If only one arg, then it (crn) has to be three digit value
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
38 # specifying the location in digit 1 (rows) and 2 (columns) and digit
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
39 # 3 is the plot index
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
40 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
41 # The plot index runs row-wise,i.e., first all the columns in a row
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
42 # are filled and then the next row is filled
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
43 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
44 # For example, plot with 4 X 2 grid, will have plot indices running as
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
45 # follows:
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
46 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
47 # -----------------------------------
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
48 # | | | | |
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
49 # | 1 | 2 | 3 | 4 |
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
50 # | | | | |
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
51 # -----------------------------------
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
52 # | | | | |
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
53 # | 5 | 6 | 7 | 8 |
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
54 # | | | | |
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
55 # -----------------------------------
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
56 #
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
57
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
58 # Written by Vinayak Dutt, Dutt.Vinayak@mayo.EDU
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
59
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
60 # global variables to keep track of multiplot options
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
61
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
62 global multiplot_mode
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
63 global multi_xsize multi_ysize
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
64 global multi_xn multi_yn
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
65 global multi_xi multi_yi
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
66
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
67 # This is a real kludge. We gnuplot should be made so that replot can
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
68 # be executed while doing multiple plots...
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
69
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
70 global multiplot_save_auto_replot = automatic_replot
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
71
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
72 if (nargin != 3 && nargin != 1)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
73 usage ("subplot (rows, columns, index) or subplot (rcn)");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
74 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
75
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
76 if ((isstr (automatic_replot) && strcmp (automatic_replot, "true"))
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
77 || automatic_replot)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
78 warning ("turning off automatic replot for multiplot mode");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
79 multiplot_save_auto_replot = automatic_replot;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
80 automatic_replot = 0;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
81 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
82
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
83 if (nargin == 1)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
84
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
85 if (! is_scalar (rows))
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
86 error ("subplot: input rcn has to be a scalar");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
87 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
88
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
89 xnp = rows;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
90 rows = round (xnp/100);
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
91 columns = round ((xnp - 100*rows)/10);
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
92 index = xnp - 10*columns - 100*rows;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
93
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
94 elseif (! (is_scalar (columns) && is_scalar (rows) && is_scalar (index)))
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
95 error ("subplot: columns, rows, and index have to be scalars");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
96 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
97
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
98 columns = round (columns);
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
99 rows = round (rows);
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
100 index = round (index);
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
101
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
102 if (index > columns*rows)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
103 error ("subplot: index must be less than columns*rows");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
104 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
105
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
106 if (columns < 1 || rows < 1 || index < 1)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
107 error ("subplot: columns,rows,index must be be positive");
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
108 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
109
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
110 if (columns*rows == 1)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
111
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
112 # switching to single plot ?
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
113
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
114 set nomultiplot;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
115 set size 1,1
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
116 set origin 0,0
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
117
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
118 multi_xn = 1;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
119 multi_yn = 1;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
120 multiplot_mode = 0;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
121
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
122 # Someone may have reset it betweeen calls...
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
123
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
124 if (! isstr (automatic_replot) && ! automatic_replot)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
125 automatic_replot = multiplot_save_auto_replot;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
126 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
127
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
128 return;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
129
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
130 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
131
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
132 # doing multiplot plots
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
133
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
134 doagain = 0;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
135
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
136 if (exist ("multiplot_mode") != 1)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
137 doagain = 1;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
138 elseif (multiplot_mode != 1 || multi_xn != columns || multi_yn != rows)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
139 doagain = 1;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
140 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
141
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
142 if (doagain)
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
143
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
144 multiplot_mode = 1;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
145 multi_xn = columns;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
146 multi_yn = rows;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
147 multi_xsize = 1.0 ./ columns;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
148 multi_ysize = 1.0 ./ rows;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
149
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
150 set multiplot;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
151
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
152 eval (sprintf ("set size %g, %g", multi_xsize, multi_ysize));
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
153
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
154 endif
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
155
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
156 # get the sub plot location
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
157
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
158 yp = round ((index-1)/columns);
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
159 xp = index - yp*columns - 1;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
160 multi_xi = ++xp;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
161 multi_yi = ++yp;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
162
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
163 # set the origin
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
164
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
165 xo = (xp - 1.0)*multi_xsize;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
166 yo = (rows - yp)*multi_ysize;
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
167
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
168 eval (sprintf ("set origin %g, %g", xo, yo));
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
169
749b8b19733f [project @ 1995-10-06 03:10:34 by jwe]
jwe
parents:
diff changeset
170 endfunction