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

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