Mercurial > hg > octave-nkf
annotate scripts/plot/plotyy.m @ 12437:a754c2d8a13f
Modify demo scripts to allow conventient conversion to Matlab compatible syntax.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Thu, 10 Feb 2011 18:48:36 -0500 |
parents | e916491cbb99 |
children | d0b799dafede |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2007-2011 David Bateman |
7195 | 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 3 of the License, or (at | |
8 ## your option) 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, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} plotyy (@var{x1}, @var{y1}, @var{x2}, @var{y2}) |
7195 | 21 ## @deftypefnx {Function File} {} plotyy (@dots{}, @var{fun}) |
22 ## @deftypefnx {Function File} {} plotyy (@dots{}, @var{fun1}, @var{fun2}) | |
23 ## @deftypefnx {Function File} {} plotyy (@var{h}, @dots{}) | |
24 ## @deftypefnx {Function File} {[@var{ax}, @var{h1}, @var{h2}] =} plotyy (@dots{}) | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## Plots two sets of data with independent y-axes. The arguments @var{x1} and |
7195 | 26 ## @var{y1} define the arguments for the first plot and @var{x1} and @var{y2} |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
27 ## for the second. |
7195 | 28 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
29 ## By default the arguments are evaluated with |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## @code{feval (@@plot, @var{x}, @var{y})}. However the type of plot can be |
7195 | 31 ## modified with the @var{fun} argument, in which case the plots are |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
32 ## generated by @code{feval (@var{fun}, @var{x}, @var{y})}. @var{fun} can be |
7195 | 33 ## a function handle, an inline function or a string of a function name. |
34 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
35 ## The function to use for each of the plots can be independently defined |
7195 | 36 ## with @var{fun1} and @var{fun2}. |
37 ## | |
38 ## If given, @var{h} defines the principal axis in which to plot the @var{x1} | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
39 ## and @var{y1} data. The return value @var{ax} is a two element vector with |
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
40 ## the axis handles of the two plots. @var{h1} and @var{h2} are handles to |
7195 | 41 ## the objects generated by the plot commands. |
42 ## | |
43 ## @example | |
44 ## @group | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
45 ## x = 0:0.1:2*pi; |
7195 | 46 ## y1 = sin (x); |
7196 | 47 ## y2 = exp (x - 1); |
48 ## ax = plotyy (x, y1, x - 1, y2, @@plot, @@semilogy); | |
7195 | 49 ## xlabel ("X"); |
50 ## ylabel (ax(1), "Axis 1"); | |
51 ## ylabel (ax(2), "Axis 2"); | |
52 ## @end group | |
53 ## @end example | |
54 ## @end deftypefn | |
55 | |
56 function [Ax, H1, H2] = plotyy (varargin) | |
57 | |
7665
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
58 ## Don't use __plt_get_axis_arg__ here as ax is a two vector for plotyy |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
59 if (nargin > 1 && length (varargin{1}) == 2 && ishandle(varargin{1}(1)) |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10950
diff
changeset
|
60 && ishandle(varargin{1}(2)) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10950
diff
changeset
|
61 && all (floor (varargin{1}) != varargin{1})) |
7665
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
62 obj1 = get (varargin{1}(1)); |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
63 obj2 = get (varargin{1}(2)); |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
64 if (strcmp (obj1.type, "axes") || strcmp (obj2.type, "axes")) |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
65 ax = [obj1, obj2]; |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
66 varargin(1) = []; |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
67 if (isempty (varargin)) |
10549 | 68 varargin = {}; |
7665
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
69 endif |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
70 else |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
71 error ("plotyy: expecting first argument to be axes handle"); |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
72 endif |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
73 else |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
74 f = get (0, "currentfigure"); |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
75 if (isempty (f)) |
9346
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
76 f = figure (); |
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
77 endif |
9349
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
78 ca = get (f, "currentaxes"); |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
79 if (isempty (ca)) |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
80 ax = []; |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
81 elseif (strcmp (get (ca, "tag"), "plotyy")); |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
82 ax = get (ca, "__plotyy_axes__"); |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
83 else |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
84 ax = ca; |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
85 endif |
9346
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
86 if (length (ax) > 2) |
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
87 for i = 3 : length (ax) |
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
88 delete (ax (i)); |
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
89 endfor |
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
90 ax = ax(1:2); |
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
91 elseif (length (ax) == 1) |
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
92 ax(2) = axes (); |
d50c3d8efe71
plotyy.m: Correct behavior when there is no currentfigure.
Ben Abbott <bpabbott@mac.com>
parents:
9040
diff
changeset
|
93 elseif (isempty (ax)) |
7665
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
94 ax(1) = axes (); |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
95 ax(2) = axes (); |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
96 endif |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
97 if (nargin < 2) |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
98 varargin = {}; |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
99 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
100 endif |
7215 | 101 |
102 if (nargin < 4) | |
103 print_usage (); | |
104 endif | |
7216 | 105 |
7215 | 106 oldh = gca (); |
107 unwind_protect | |
108 [ax, h1, h2] = __plotyy__ (ax, varargin{:}); | |
109 unwind_protect_cleanup | |
8237
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
110 ## Only change back to the old axis if we didn't delete it |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
111 if (ishandle(oldh) && strcmp (get (oldh, "type"), "axes")) |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
112 axes (oldh); |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
113 endif |
7215 | 114 end_unwind_protect |
7195 | 115 |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
116 set (ax, "activepositionproperty", "position"); |
10931
a72d53df4fa6
Treatment of activepositionproperty for gnuplot.
Ben Abbott <bpabbott@mac.com>
parents:
10914
diff
changeset
|
117 |
7195 | 118 if (nargout > 0) |
119 Ax = ax; | |
120 H1 = h1; | |
121 H2 = h2; | |
122 endif | |
7196 | 123 |
7195 | 124 endfunction |
125 | |
126 function [ax, h1, h2] = __plotyy__ (ax, x1, y1, x2, y2, varargin) | |
127 if (nargin > 5) | |
128 fun1 = varargin{1}; | |
129 else | |
130 fun1 = @plot; | |
131 endif | |
132 if (nargin > 6) | |
133 fun2 = varargin{2}; | |
134 else | |
135 fun2 = fun1; | |
136 endif | |
137 | |
138 xlim = [min([x1(:); x2(:)]), max([x1(:); x2(:)])]; | |
139 | |
8237
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
140 if (ishandle(ax(1)) && strcmp (get (ax(1), "type"), "axes")) |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
141 axes (ax(1)); |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
142 else |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
143 ax(1) = axes (); |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
144 endif |
7665
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
145 newplot (); |
7195 | 146 h1 = feval (fun1, x1, y1); |
7220 | 147 |
148 set (ax(1), "ycolor", getcolor (h1(1))); | |
7195 | 149 set (ax(1), "xlim", xlim); |
10136
ee18258bc002
Also treat white figure and axes color properties
David Bateman <dbateman@free.fr>
parents:
9353
diff
changeset
|
150 set (ax(1), "color", "none"); |
7195 | 151 |
152 cf = gcf (); | |
153 set (cf, "nextplot", "add"); | |
8237
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
154 |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
155 if (ishandle(ax(2)) && strcmp (get (ax(2), "type"), "axes")) |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
156 axes (ax(2)); |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
157 else |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
158 ax(2) = axes (); |
52f2fba4f3f8
Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents:
8208
diff
changeset
|
159 endif |
7665
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
160 newplot (); |
aead4b9d026b
Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents:
7314
diff
changeset
|
161 |
7195 | 162 colors = get (ax(1), "colororder"); |
163 set (ax(2), "colororder", [colors(2:end,:); colors(1,:)]); | |
164 | |
165 h2 = feval (fun2, x2, y2); | |
7206 | 166 set (ax(2), "yaxislocation", "right"); |
7220 | 167 set (ax(2), "ycolor", getcolor (h2(1))); |
7240 | 168 set (ax(2), "position", get (ax(1), "position")); |
7195 | 169 set (ax(2), "xlim", xlim); |
7240 | 170 set (ax(2), "color", "none"); |
12128
e916491cbb99
plotyy.m: Set box property to off to allow both y-axes colors to be visible for OpenGL backends.
Ben Abbott <bpabbott@mac.com>
parents:
11589
diff
changeset
|
171 set (ax(2), "box", "off"); |
8208 | 172 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
173 ## Add invisible text objects that when destroyed, |
8208 | 174 ## also remove the other axis |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
175 t1 = text (0, 0, "", "parent", ax(1), "tag", "plotyy", |
10549 | 176 "handlevisibility", "off", "visible", "off", |
177 "xliminclude", "off", "yliminclude", "off"); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
178 t2 = text (0, 0, "", "parent", ax(2), "tag", "plotyy", |
10549 | 179 "handlevisibility", "off", "visible", "off", |
180 "xliminclude", "off", "yliminclude", "off"); | |
8208 | 181 |
182 set (t1, "deletefcn", {@deleteplotyy, ax(2), t2}); | |
183 set (t2, "deletefcn", {@deleteplotyy, ax(1), t1}); | |
184 | |
185 addlistener (ax(1), "position", {@update_position, ax(2)}); | |
186 addlistener (ax(2), "position", {@update_position, ax(1)}); | |
187 addlistener (ax(1), "view", {@update_position, ax(2)}); | |
188 addlistener (ax(2), "view", {@update_position, ax(1)}); | |
10226
2884758e265b
Replace dataaspectratio props with plotboxaspectratio props.
Ben Abbott <bpabbott@mac.com>
parents:
10136
diff
changeset
|
189 addlistener (ax(1), "plotboxaspectratio", {@update_position, ax(2)}); |
2884758e265b
Replace dataaspectratio props with plotboxaspectratio props.
Ben Abbott <bpabbott@mac.com>
parents:
10136
diff
changeset
|
190 addlistener (ax(2), "plotboxaspectratio", {@update_position, ax(1)}); |
10529
7147078550fe
plotyy.m: Add listener for dataaspectratiomode.
Ben Abbott <bpabbott@mac.com>
parents:
10226
diff
changeset
|
191 addlistener (ax(1), "plotboxaspectratiomode", {@update_position, ax(2)}); |
7147078550fe
plotyy.m: Add listener for dataaspectratiomode.
Ben Abbott <bpabbott@mac.com>
parents:
10226
diff
changeset
|
192 addlistener (ax(2), "plotboxaspectratiomode", {@update_position, ax(1)}); |
8208 | 193 |
194 ## Tag the plotyy axes, so we can use that information | |
195 ## not to mirror the y axis tick marks | |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
196 set (ax, "tag", "plotyy"); |
8208 | 197 |
11198
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11189
diff
changeset
|
198 ## Cross-reference one axis to the other in the userdata |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11189
diff
changeset
|
199 set (ax(1), "userdata", ax(2)); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11189
diff
changeset
|
200 set (ax(2), "userdata", ax(1)); |
9f080d23396f
Fix multi-parented legends with the gnuplot backend (fixes #30461 and #31522)
David Bateman <dbateman@free.fr>
parents:
11189
diff
changeset
|
201 |
9349
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
202 ## Store the axes handles for the sister axes. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
203 try |
10950
c9786e03670c
Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
204 addproperty ("__plotyy_axes__", ax(1), "data", ax); |
c9786e03670c
Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
205 catch |
c9786e03670c
Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
206 set (ax(1), "__plotyy_axes__", ax); |
c9786e03670c
Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
207 end_try_catch |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
208 try |
10950
c9786e03670c
Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
209 addproperty ("__plotyy_axes__", ax(2), "data", ax); |
c9786e03670c
Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
210 catch |
c9786e03670c
Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
211 set (ax(2), "__plotyy_axes__", ax); |
c9786e03670c
Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents:
10949
diff
changeset
|
212 end_try_catch |
8208 | 213 endfunction |
214 | |
215 %!demo | |
8790
a013ff655ca4
Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents:
8769
diff
changeset
|
216 %! clf |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
217 %! x = 0:0.1:2*pi; |
8208 | 218 %! y1 = sin (x); |
219 %! y2 = exp (x - 1); | |
220 %! ax = plotyy (x, y1, x - 1, y2, @plot, @semilogy); | |
221 %! xlabel ("X"); | |
222 %! ylabel (ax(1), "Axis 1"); | |
223 %! ylabel (ax(2), "Axis 2"); | |
10914
c0434971d0a8
plotyy.m: Modified demo for changeset 10912 9abc67b4bd4f.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
224 %! axes (ax(1)) |
12437
a754c2d8a13f
Modify demo scripts to allow conventient conversion to Matlab compatible syntax.
Ben Abbott <bpabbott@mac.com>
parents:
12128
diff
changeset
|
225 %! text (0.5, 0.5, "Left Axis", ... |
10914
c0434971d0a8
plotyy.m: Modified demo for changeset 10912 9abc67b4bd4f.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
226 %! "color", [0 0 1], "horizontalalignment", "center") |
c0434971d0a8
plotyy.m: Modified demo for changeset 10912 9abc67b4bd4f.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
227 %! axes (ax(2)) |
12437
a754c2d8a13f
Modify demo scripts to allow conventient conversion to Matlab compatible syntax.
Ben Abbott <bpabbott@mac.com>
parents:
12128
diff
changeset
|
228 %! text (4.5, 80, "Right Axis", ... |
10914
c0434971d0a8
plotyy.m: Modified demo for changeset 10912 9abc67b4bd4f.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
229 %! "color", [0 0.5 0], "horizontalalignment", "center") |
8208 | 230 |
9349
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
231 %!demo |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
232 %! clf |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
233 %! x = linspace (-1, 1, 201); |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
234 %! subplot (2, 2, 1) |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
235 %! plotyy (x, sin(pi*x), x, 10*cos(pi*x)) |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
236 %! subplot (2, 2, 2) |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
237 %! surf (peaks (25)) |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
238 %! subplot (2, 2, 3) |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
239 %! contour (peaks (25)) |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
240 %! subplot (2, 2, 4) |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
241 %! plotyy (x, 10*sin(2*pi*x), x, cos(2*pi*x)) |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
242 %! axis square |
93664cbb732c
plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents:
9346
diff
changeset
|
243 |
8208 | 244 function deleteplotyy (h, d, ax2, t2) |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10950
diff
changeset
|
245 if (ishandle (ax2) && strcmp (get (ax2, "type"), "axes") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10950
diff
changeset
|
246 && (isempty (gcbf()) || strcmp (get (gcbf(), "beingdeleted"),"off")) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10950
diff
changeset
|
247 && strcmp (get (ax2, "beingdeleted"), "off")) |
8208 | 248 set (t2, "deletefcn", []); |
249 delete (ax2); | |
250 endif | |
251 endfunction | |
252 | |
253 function update_position (h, d, ax2) | |
254 persistent recursion = false; | |
255 | |
256 ## Don't allow recursion | |
257 if (! recursion) | |
258 unwind_protect | |
259 recursion = true; | |
260 position = get (h, "position"); | |
261 view = get (h, "view"); | |
10226
2884758e265b
Replace dataaspectratio props with plotboxaspectratio props.
Ben Abbott <bpabbott@mac.com>
parents:
10136
diff
changeset
|
262 plotboxaspectratio = get (h, "plotboxaspectratio"); |
2884758e265b
Replace dataaspectratio props with plotboxaspectratio props.
Ben Abbott <bpabbott@mac.com>
parents:
10136
diff
changeset
|
263 plotboxaspectratiomode = get (h, "plotboxaspectratiomode"); |
8208 | 264 oldposition = get (ax2, "position"); |
265 oldview = get (ax2, "view"); | |
10226
2884758e265b
Replace dataaspectratio props with plotboxaspectratio props.
Ben Abbott <bpabbott@mac.com>
parents:
10136
diff
changeset
|
266 oldplotboxaspectratio = get (ax2, "plotboxaspectratio"); |
2884758e265b
Replace dataaspectratio props with plotboxaspectratio props.
Ben Abbott <bpabbott@mac.com>
parents:
10136
diff
changeset
|
267 oldplotboxaspectratiomode = get (ax2, "plotboxaspectratiomode"); |
9353
335dc62068a8
plotyy.m: Consider dataaspectratiomode before changing dataaspectratio.
Ben Abbott <bpabbott@mac.com>
parents:
9349
diff
changeset
|
268 if (! (isequal (position, oldposition) && isequal (view, oldview))) |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
269 set (ax2, "position", position, "view", view); |
9353
335dc62068a8
plotyy.m: Consider dataaspectratiomode before changing dataaspectratio.
Ben Abbott <bpabbott@mac.com>
parents:
9349
diff
changeset
|
270 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
271 if (! (isequal (plotboxaspectratio, oldplotboxaspectratio) |
10549 | 272 && isequal (plotboxaspectratiomode, oldplotboxaspectratiomode))) |
273 set (ax2, "plotboxaspectratio", plotboxaspectratio); | |
274 set (ax2, "plotboxaspectratiomode", plotboxaspectratiomode); | |
8208 | 275 endif |
276 unwind_protect_cleanup | |
277 recursion = false; | |
278 end_unwind_protect | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
279 endif |
7195 | 280 endfunction |
7220 | 281 |
282 function color = getcolor (ax) | |
283 obj = get (ax); | |
284 if (isfield (obj, "color")) | |
285 color = obj.color; | |
286 elseif (isfield (obj, "facecolor") && ! ischar (obj.facecolor)) | |
287 color = obj.facecolor; | |
288 elseif (isfield (obj, "edgecolor") && ! ischar (obj.edgecolor)) | |
289 color = obj.edgecolor; | |
290 else | |
291 color = [0, 0, 0]; | |
292 endif | |
293 endfunction | |
7245 | 294 |