7017
|
1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2004, |
|
2 ## 2005, 2006, 2007 John W. Eaton |
2313
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
2313
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
245
|
19 |
3368
|
20 ## -*- texinfo -*- |
6895
|
21 ## @deftypefn {Function File} {} plot (@var{y}) |
|
22 ## @deftypefnx {Function File} {} plot (@var{x}, @var{y}) |
|
23 ## @deftypefnx {Function File} {} plot (@var{x}, @var{y}, @var{property}, @var{value}, @dots{}) |
|
24 ## @deftypefnx {Function File} {} plot (@var{x}, @var{y}, @var{fmt}) |
|
25 ## @deftypefnx {Function File} {} plot (@var{h}, @dots{}) |
|
26 ## Produces two-dimensional plots. Many different combinations of |
|
27 ## arguments are possible. The simplest form is |
3426
|
28 ## |
3368
|
29 ## @example |
|
30 ## plot (@var{y}) |
|
31 ## @end example |
3426
|
32 ## |
3368
|
33 ## @noindent |
|
34 ## where the argument is taken as the set of @var{y} coordinates and the |
|
35 ## @var{x} coordinates are taken to be the indices of the elements, |
|
36 ## starting with 1. |
3426
|
37 ## |
5798
|
38 ## To save a plot, in one of several image formats such as PostScript |
|
39 ## or PNG, use the @code{print} command. |
|
40 ## |
3368
|
41 ## If more than one argument is given, they are interpreted as |
3426
|
42 ## |
3368
|
43 ## @example |
6895
|
44 ## plot (@var{y}, @var{property}, @var{value}, @dots{}) |
3368
|
45 ## @end example |
3426
|
46 ## |
3368
|
47 ## @noindent |
6895
|
48 ## or |
6459
|
49 ## |
|
50 ## @example |
|
51 ## plot (@var{x}, @var{y}, @var{property}, @var{value}, @dots{}) |
|
52 ## @end example |
|
53 ## |
|
54 ## @noindent |
6895
|
55 ## or |
|
56 ## |
|
57 ## @example |
|
58 ## plot (@var{x}, @var{y}, @var{fmt}, @dots{}) |
|
59 ## @end example |
|
60 ## |
|
61 ## @noindent |
|
62 ## and so on. Any number of argument sets may appear. The @var{x} and |
|
63 ## @var{y} values are interpreted as follows: |
3426
|
64 ## |
3368
|
65 ## @itemize @bullet |
|
66 ## @item |
|
67 ## If a single data argument is supplied, it is taken as the set of @var{y} |
|
68 ## coordinates and the @var{x} coordinates are taken to be the indices of |
|
69 ## the elements, starting with 1. |
3426
|
70 ## |
3368
|
71 ## @item |
6672
|
72 ## If the @var{x} is a vector and @var{y} is a matrix, then |
6177
|
73 ## the columns (or rows) of @var{y} are plotted versus @var{x}. |
2311
|
74 ## (using whichever combination matches, with columns tried first.) |
3426
|
75 ## |
3368
|
76 ## @item |
6177
|
77 ## If the @var{x} is a matrix and @var{y} is a vector, |
|
78 ## @var{y} is plotted versus the columns (or rows) of @var{x}. |
2311
|
79 ## (using whichever combination matches, with columns tried first.) |
3426
|
80 ## |
3368
|
81 ## @item |
|
82 ## If both arguments are vectors, the elements of @var{y} are plotted versus |
|
83 ## the elements of @var{x}. |
3426
|
84 ## |
3368
|
85 ## @item |
|
86 ## If both arguments are matrices, the columns of @var{y} are plotted |
|
87 ## versus the columns of @var{x}. In this case, both matrices must have |
|
88 ## the same number of rows and columns and no attempt is made to transpose |
|
89 ## the arguments to make the number of rows match. |
3426
|
90 ## |
2311
|
91 ## If both arguments are scalars, a single point is plotted. |
3368
|
92 ## @end itemize |
3426
|
93 ## |
6895
|
94 ## Multiple property-value pairs may be specified, but they must appear |
|
95 ## in pairs. These arguments are applied to the lines drawn by |
|
96 ## @code{plot}. |
|
97 ## |
3368
|
98 ## If the @var{fmt} argument is supplied, it is interpreted as |
|
99 ## follows. If @var{fmt} is missing, the default gnuplot line style |
|
100 ## is assumed. |
3426
|
101 ## |
3368
|
102 ## @table @samp |
|
103 ## @item - |
|
104 ## Set lines plot style (default). |
3426
|
105 ## |
3368
|
106 ## @item . |
|
107 ## Set dots plot style. |
3426
|
108 ## |
3368
|
109 ## @item ^ |
|
110 ## Set impulses plot style. |
3426
|
111 ## |
3368
|
112 ## @item L |
|
113 ## Set steps plot style. |
3426
|
114 ## |
3368
|
115 ## @item @var{n} |
|
116 ## Interpreted as the plot color if @var{n} is an integer in the range 1 to |
|
117 ## 6. |
3426
|
118 ## |
3368
|
119 ## @item @var{nm} |
|
120 ## If @var{nm} is a two digit integer and @var{m} is an integer in the |
|
121 ## range 1 to 6, @var{m} is interpreted as the point style. This is only |
|
122 ## valid in combination with the @code{@@} or @code{-@@} specifiers. |
3426
|
123 ## |
3368
|
124 ## @item @var{c} |
6177
|
125 ## If @var{c} is one of @code{"k"} (black), @code{"r"} (red), @code{"g"} |
|
126 ## (green), @code{"b"} (blue), @code{"m"} (magenta), @code{"c"} (cyan), |
|
127 ## or @code{"w"} (white), it is interpreted as the line plot color. |
3426
|
128 ## |
3717
|
129 ## @item ";title;" |
|
130 ## Here @code{"title"} is the label for the key. |
|
131 ## |
3368
|
132 ## @item + |
|
133 ## @itemx * |
|
134 ## @itemx o |
|
135 ## @itemx x |
|
136 ## Used in combination with the points or linespoints styles, set the point |
|
137 ## style. |
|
138 ## @end table |
3426
|
139 ## |
6895
|
140 ## The @var{fmt} argument may also be used to assign key titles. |
3683
|
141 ## To do so, include the desired title between semi-colons after the |
|
142 ## formatting sequence described above, e.g. "+3;Key Title;" |
|
143 ## Note that the last semi-colon is required and will generate an error if |
|
144 ## it is left out. |
|
145 ## |
3368
|
146 ## Here are some plot examples: |
3426
|
147 ## |
3368
|
148 ## @example |
|
149 ## plot (x, y, "@@12", x, y2, x, y3, "4", x, y4, "+") |
|
150 ## @end example |
3426
|
151 ## |
3368
|
152 ## This command will plot @code{y} with points of type 2 (displayed as |
|
153 ## @samp{+}) and color 1 (red), @code{y2} with lines, @code{y3} with lines of |
|
154 ## color 4 (magenta) and @code{y4} with points displayed as @samp{+}. |
3426
|
155 ## |
3368
|
156 ## @example |
6459
|
157 ## plot (b, "*", "markersize", 3) |
3368
|
158 ## @end example |
3426
|
159 ## |
6672
|
160 ## This command will plot the data in the variable @code{b}, |
6459
|
161 ## with points displayed as @samp{*} with a marker size of 3. |
3683
|
162 ## |
|
163 ## @example |
|
164 ## t = 0:0.1:6.3; |
|
165 ## plot (t, cos(t), "-;cos(t);", t, sin(t), "+3;sin(t);"); |
|
166 ## @end example |
|
167 ## |
|
168 ## This will plot the cosine and sine functions and label them accordingly |
|
169 ## in the key. |
6820
|
170 ## |
|
171 ## If the first argument is an axis handle, then plot into these axes, |
|
172 ## rather than the current axis handle returned by @code{gca}. |
6895
|
173 ## @seealso{semilogx, semilogy, loglog, polar, mesh, contour, bar, |
|
174 ## stairs, errorbar, xlabel, ylabel, title, print} |
3368
|
175 ## @end deftypefn |
4
|
176 |
2314
|
177 ## Author: jwe |
|
178 |
6302
|
179 function retval = plot (varargin) |
4
|
180 |
6820
|
181 if (isscalar (varargin{1}) && ishandle (varargin{1})) |
7208
|
182 h = varargin{1}; |
6828
|
183 if (! strcmp (get (h, "type"), "axes")) |
6820
|
184 error ("plot: expecting first argument to be an axes object"); |
|
185 endif |
|
186 oldh = gca (); |
|
187 unwind_protect |
|
188 axes (h); |
|
189 newplot (); |
|
190 tmp = __plt__ ("plot", h, varargin{2:end}); |
|
191 unwind_protect_cleanup |
|
192 axes (oldh); |
|
193 end_unwind_protect |
|
194 else |
|
195 newplot (); |
|
196 tmp = __plt__ ("plot", gca (), varargin{:}); |
|
197 endif |
6302
|
198 |
|
199 if (nargout > 0) |
|
200 retval = tmp; |
|
201 endif |
4
|
202 |
|
203 endfunction |