PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/tpikonen/octave-forge/extra/graceplot/alternatives/subplot.m

#
MATLAB | 185 lines | 148 code | 37 blank | 0 comment | 10 complexity | af946465b4b12da2b8ec3337213c3b84 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, GPL-3.0, LGPL-3.0
  1. ## Copyright (C) 1996, 1997 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
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ## General Public License 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. ## -*- texinfo -*-
  20. ## @deftypefn {Function File} {} subplot (@var{rows}, @var{cols}, @var{index})
  21. ## @deftypefnx {Function File} {} subplot (@var{rcn})
  22. ## Sets the Grace plot in multiplot mode and plots in location
  23. ## given by index (there are @var{cols} by @var{rows} subwindows).
  24. ##
  25. ## Input:
  26. ##
  27. ## @table @var
  28. ## @item rows
  29. ## Number of rows in subplot grid.
  30. ##
  31. ## @item columns
  32. ## Number of columns in subplot grid.
  33. ##
  34. ## @item index
  35. ## Index of subplot where to make the next plot.
  36. ## @end table
  37. ##
  38. ## If only one argument is supplied, then it must be a three digit value
  39. ## specifying the location in digits 1 (rows) and 2 (columns) and the plot
  40. ## index in digit 3.
  41. ##
  42. ## The plot index runs row-wise. First all the columns in a row are filled
  43. ## and then the next row is filled.
  44. ##
  45. ## For example, a plot with 4 by 2 grid will have plot indices running as
  46. ## follows:
  47. ## @iftex
  48. ## @tex
  49. ## \vskip 10pt
  50. ## \hfil\vbox{\offinterlineskip\hrule
  51. ## \halign{\vrule#&&\qquad\hfil#\hfil\qquad\vrule\cr
  52. ## height13pt&1&2&3&4\cr height12pt&&&&\cr\noalign{\hrule}
  53. ## height13pt&5&6&7&8\cr height12pt&&&&\cr\noalign{\hrule}}}
  54. ## \hfil
  55. ## \vskip 10pt
  56. ## @end tex
  57. ## @end iftex
  58. ## @ifinfo
  59. ## @display
  60. ## @group
  61. ## +-----+-----+-----+-----+
  62. ## | 1 | 2 | 3 | 4 |
  63. ## +-----+-----+-----+-----+
  64. ## | 5 | 6 | 7 | 8 |
  65. ## +-----+-----+-----+-----+
  66. ## @end group
  67. ## @end display
  68. ## @end ifinfo
  69. ## @end deftypefn
  70. ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
  71. ## Adapted-By: jwe
  72. ## Modified to work with Grace by Teemu Ikonen <tpikonen@pcu.helsinki.fi>
  73. ## Created: 8.8.2003
  74. function subplot (rows, columns, index)
  75. ## global variables to keep track of multiplot options
  76. global __grmultiplot_mode__ = 0;
  77. global __grmultiplot_xn__;
  78. global __grmultiplot_yn__;
  79. # global __multiplot_mode__ = 0;
  80. # global __multiplot_xsize__;
  81. # global __multiplot_ysize__;
  82. # global __multiplot_xn__;
  83. # global __multiplot_yn__;
  84. # global __multiplot_xi__;
  85. # global __multiplot_yi__;
  86. if (nargin != 3 && nargin != 1)
  87. usage ("subplot (rows, columns, index) or subplot (rcn)");
  88. endif
  89. if (nargin == 1)
  90. if (! (isscalar (rows) && rows >= 0))
  91. error ("subplot: input rcn has to be a positive scalar");
  92. endif
  93. tmp = rows;
  94. index = rem (tmp, 10);
  95. tmp = (tmp - index) / 10;
  96. columns = rem (tmp, 10);
  97. tmp = (tmp - columns) / 10;
  98. rows = rem (tmp, 10);
  99. elseif (! (isscalar (columns) && isscalar (rows) && isscalar (index)))
  100. error ("subplot: columns, rows, and index have to be scalars");
  101. endif
  102. columns = round (columns);
  103. rows = round (rows);
  104. index = round (index);
  105. if (index > columns*rows)
  106. error ("subplot: index must be less than columns*rows");
  107. endif
  108. if (columns < 1 || rows < 1 || index < 1)
  109. error ("subplot: columns,rows,index must be be positive");
  110. endif
  111. if (columns*rows == 1)
  112. ## switching to single plot ?
  113. oneplot ();
  114. ## XXX FIXME XXX -- do we really need to reset these here?
  115. # __multiplot_xn__ = 1;
  116. # __multiplot_yn__ = 1;
  117. else
  118. ## doing multiplot plots
  119. if ( (!__grmultiplot_mode__)
  120. || (__grmultiplot_xn__ != columns)
  121. || (__grmultiplot_yn__ != rows) )
  122. multiplot(columns, rows);
  123. endif
  124. __grsetgraph__(index-1);
  125. # if (! __multiplot_mode__
  126. # || __multiplot_xn__ != columns
  127. # || __multiplot_yn__ != rows)
  128. # __multiplot_mode__ = 1;
  129. # __multiplot_xn__ = columns;
  130. # __multiplot_yn__ = rows;
  131. # __multiplot_xsize__ = 1.0 ./ columns;
  132. # __multiplot_ysize__ = 1.0 ./ rows;
  133. # gnuplot_command_replot = "cle;rep";
  134. # gset multiplot;
  135. # eval (sprintf ("gset size %g, %g", __multiplot_xsize__,
  136. # __multiplot_ysize__));
  137. # endif
  138. # ## get the sub plot location
  139. # yp = fix ((index-1)/columns);
  140. # xp = index - yp*columns - 1;
  141. # __multiplot_xi__ = ++xp;
  142. # __multiplot_yi__ = ++yp;
  143. # ## set the origin
  144. # xo = (xp - 1.0) * __multiplot_xsize__;
  145. # yo = (rows - yp) * __multiplot_ysize__;
  146. # eval (sprintf ("gset origin %g, %g", xo, yo));
  147. endif
  148. endfunction