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