/branches/dyndrv_1/bindings/octave/PLplot/subplot.m

# · MATLAB · 127 lines · 107 code · 20 blank · 0 comment · 10 complexity · 40f08694bb41caa0e0bdf81914cf670d MD5 · raw file

  1. ## Copyright (C) 1996 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. ## usage: subplot (rows, columns, index)
  20. ## subplot (rcn)
  21. ##
  22. ## Sets plot in multiplot mode and plots in location
  23. ## given by index (there are columns X rows subwindows)
  24. ##
  25. ## Input:
  26. ##
  27. ## rows : number of rows in subplot grid
  28. ## columns: number of columns in subplot grid
  29. ## index : index of subplot where to make the next plot
  30. ##
  31. ## If only one arg, then it (crn) has to be three digit value
  32. ## specifying the location in digit 1 (rows) and 2 (columns) and digit
  33. ## 3 is the plot index
  34. ##
  35. ## The plot index runs row-wise,i.e., first all the columns in a row
  36. ## are filled and then the next row is filled
  37. ##
  38. ## For example, plot with 4 X 2 grid, will have plot indices running as
  39. ## follows:
  40. ##
  41. ## -----------------------------------
  42. ## | | | | |
  43. ## | 1 | 2 | 3 | 4 |
  44. ## | | | | |
  45. ## -----------------------------------
  46. ## | | | | |
  47. ## | 5 | 6 | 7 | 8 |
  48. ## | | | | |
  49. ## -----------------------------------
  50. ##
  51. ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
  52. ## Adapted-By: jwe
  53. ## Modified: jc
  54. function subplot (rows, columns, index)
  55. global __pl __pl_inited
  56. if (!exist("__pl_inited") || plglevel == 0)
  57. figure(0)
  58. endif
  59. __pl_strm = plgstrm + 1;
  60. if (nargin != 3 && nargin != 1)
  61. usage ("subplot (rows, columns, index) or subplot (rcn)");
  62. endif
  63. if (nargin == 1)
  64. if (! (is_scalar (rows) && rows >= 0))
  65. error ("subplot: input rcn has to be a positive scalar");
  66. endif
  67. tmp = rows;
  68. index = rem (tmp, 10);
  69. tmp = (tmp - index) / 10;
  70. columns = rem (tmp, 10);
  71. tmp = (tmp - columns) / 10;
  72. rows = rem (tmp, 10);
  73. elseif (! (is_scalar (columns) && is_scalar (rows) && is_scalar (index)))
  74. error ("subplot: columns, rows, and index have to be scalars");
  75. endif
  76. columns = round (columns);
  77. rows = round (rows);
  78. index = round (index);
  79. if (index > columns*rows)
  80. error ("subplot: index must be less than columns*rows");
  81. endif
  82. if (columns < 1 || rows < 1 || index < 1)
  83. error ("subplot: columns,rows,index must be be positive");
  84. endif
  85. if (columns*rows == 1) # switching to single plot
  86. plssub(1,1);
  87. else
  88. ##already in multiplot with same characteristics ?
  89. __pl.multi_cur(__pl_strm) = index;
  90. if (__pl.multi(__pl_strm) == 1 &&
  91. __pl.multi_col(__pl_strm) == columns &&
  92. __pl.multi_row(__pl_strm) == rows)
  93. pladv(index);
  94. plvpor(0,1,0,1)
  95. plwind(0,1,0,1)
  96. plcol(0); plpsty(0)
  97. plfill([0; 1; 1; 0],[0; 0; 1; 1]);
  98. plflush; pleop;
  99. else
  100. __pl.multi_col(__pl_strm) = columns;
  101. __pl.multi_row(__pl_strm) = rows;
  102. __pl.multi(__pl_strm) = 1;
  103. plssub(columns, rows);
  104. pladv(index);
  105. endif
  106. endif
  107. endfunction