annotate scripts/plot/draw/plotyy.m @ 19630:0e1f5a750d00

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Jan 2015 10:24:46 -0500
parents cafffc1b70b1 446c46af4b42
children db92e7e28e1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17572
diff changeset
1 ## Copyright (C) 2007-2013 David Bateman
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
2 ##
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
4 ##
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
8 ## your option) any later version.
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
9 ##
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
14 ##
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
18
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
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
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
21 ## @deftypefnx {Function File} {} plotyy (@dots{}, @var{fun})
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
22 ## @deftypefnx {Function File} {} plotyy (@dots{}, @var{fun1}, @var{fun2})
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
23 ## @deftypefnx {Function File} {} plotyy (@var{hax}, @dots{})
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
24 ## @deftypefnx {Function File} {[@var{ax}, @var{h1}, @var{h2}] =} plotyy (@dots{})
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
25 ## Plot two sets of data with independent y-axes and a common x-axis.
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
26 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
27 ## The arguments @var{x1} and @var{y1} define the arguments for the first plot
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
28 ## and @var{x1} and @var{y2} for the second.
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
29 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
30 ## By default the arguments are evaluated with
9040
dbd0c77e575e Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
31 ## @code{feval (@@plot, @var{x}, @var{y})}. However the type of plot can be
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
32 ## 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
33 ## generated by @code{feval (@var{fun}, @var{x}, @var{y})}. @var{fun} can be
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
34 ## a function handle, an inline function, or a string of a function name.
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
35 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
36 ## The function to use for each of the plots can be independently defined
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
37 ## with @var{fun1} and @var{fun2}.
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
38 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
39 ## If the first argument @var{hax} is an axes handle, then it defines
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
40 ## the principal axis in which to plot the @var{x1} and @var{y1} data.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
41 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
42 ## The return value @var{ax} is a vector with the axis handles of the two
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
43 ## y-axes. @var{h1} and @var{h2} are handles to the objects generated by the
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17068
diff changeset
44 ## plot commands.
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
45 ##
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
46 ## @example
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
47 ## @group
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
48 ## x = 0:0.1:2*pi;
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
49 ## y1 = sin (x);
7196
9092375e3936 [project @ 2007-11-26 23:39:26 by jwe]
jwe
parents: 7195
diff changeset
50 ## y2 = exp (x - 1);
9092375e3936 [project @ 2007-11-26 23:39:26 by jwe]
jwe
parents: 7195
diff changeset
51 ## ax = plotyy (x, y1, x - 1, y2, @@plot, @@semilogy);
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
52 ## xlabel ("X");
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
53 ## ylabel (ax(1), "Axis 1");
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
54 ## ylabel (ax(2), "Axis 2");
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
55 ## @end group
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
56 ## @end example
16814
64e7bb01fce2 doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents: 15202
diff changeset
57 ## @seealso{plot}
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
58 ## @end deftypefn
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
59
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
60 function [ax, h1, h2] = plotyy (varargin)
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
61
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
62 [hax, varargin] = __plt_get_axis_arg__ ("plotyy", varargin{:});
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
63
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
64 nargin = numel (varargin);
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
65 if (nargin < 4 || nargin > 6)
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
66 print_usage ();
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
67 endif
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7215
diff changeset
68
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
69 oldfig = [];
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
70 if (! isempty (hax))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
71 oldfig = get (0, "currentfigure");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
72 endif
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
73 unwind_protect
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
74 hax = newplot (hax);
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
75
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
76 ## FIXME: Second conditional test shouldn't be required.
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
77 ## 'cla reset' needs to delete user properties like __plotyy_axes__.
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
78 if (isprop (hax, "__plotyy_axes__")
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
79 && isaxes (get (hax, "__plotyy_axes__")) == [true true])
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
80 hax = get (hax, "__plotyy_axes__");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
81 else
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
82 hax(2) = axes ("nextplot", get (hax(1), "nextplot"));
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
83 endif
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
84
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
85 [axtmp, h1tmp, h2tmp] = __plotyy__ (hax, varargin{:});
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
86
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
87 set (gcf, "currentaxes", hax(1));
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
88
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
89 unwind_protect_cleanup
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
90 if (! isempty (oldfig))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
91 set (0, "currentfigure", oldfig);
8237
52f2fba4f3f8 Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents: 8208
diff changeset
92 endif
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
93 end_unwind_protect
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
94
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
95 if (nargout > 0)
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
96 ax = axtmp;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
97 h1 = h1tmp;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
98 h2 = h2tmp;
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
99 endif
7196
9092375e3936 [project @ 2007-11-26 23:39:26 by jwe]
jwe
parents: 7195
diff changeset
100
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
101 endfunction
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
102
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
103 function [ax, h1, h2] = __plotyy__ (ax, x1, y1, x2, y2, fun1 = @plot, fun2)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
104
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
105 if (nargin < 7)
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
106 fun2 = fun1;
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
107 endif
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
108
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
109 xlim = [min([x1(:); x2(:)]), max([x1(:); x2(:)])];
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
110
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
111 axes (ax(1));
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
112
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
113 h1 = feval (fun1, x1, y1);
7220
66081694ffb8 [project @ 2007-11-29 23:14:07 by jwe]
jwe
parents: 7216
diff changeset
114
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
115 set (ax(1), "color", "none", "ycolor", getcolor (h1(1)), "xlim", xlim);
8237
52f2fba4f3f8 Test that an axis handle actually is one before setting it in plotyy
David Bateman <dbateman@free.fr>
parents: 8208
diff changeset
116
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
117 set (gcf (), "nextplot", "add");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
118
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
119 axes (ax(2));
7665
aead4b9d026b Fix axis handle treatment in plotyy
David Bateman <dbateman@free.fr>
parents: 7314
diff changeset
120
7195
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
121 colors = get (ax(1), "colororder");
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
122 set (ax(2), "colororder", [colors(2:end,:); colors(1,:)]);
97d2da8ed746 [project @ 2007-11-26 23:13:40 by dbateman]
dbateman
parents:
diff changeset
123
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
124 if (strcmp (get (ax(1), "autopos_tag"), "subplot"))
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
125 set (ax(2), "autopos_tag", "subplot");
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
126 else
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
127 set (ax, "activepositionproperty", "position");
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
128 endif
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
129
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
130 ## Don't replace axis which has colororder property already modified
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
131 if (strcmp (get (ax(1), "nextplot"), "replace"))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
132 set (ax(2), "nextplot", "replacechildren");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
133 endif
17068
140d50ed8f22 imported patch plotyy
Rik <rik@octave.org>
parents: 16828
diff changeset
134 h2 = feval (fun2, ax(2), x2, y2);
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
135
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
136 set (ax(2), "yaxislocation", "right", "color", "none",
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
137 "ycolor", getcolor (h2(1)), "box", "off", "xlim", xlim);
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
138
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
139 if (strcmp (get(ax(1), "activepositionproperty"), "position"))
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
140 set (ax(2), "position", get (ax(1), "position"));
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
141 else
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
142 set (ax(2), {"outerposition", "looseinset"},
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
143 get (ax(1), {"outerposition", "looseinset"}));
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
144 endif
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
145
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
146 ## Restore nextplot value by copying value from axis #1
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
147 set (ax(2), "nextplot", get (ax(1), "nextplot"));
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
148
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
149 ## Add invisible text objects that when destroyed,
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
150 ## 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
151 t1 = text (0, 0, "", "parent", ax(1), "tag", "plotyy",
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
152 "visible", "off", "handlevisibility", "off",
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10529
diff changeset
153 "xliminclude", "off", "yliminclude", "off");
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
154 t2 = text (0, 0, "", "parent", ax(2), "tag", "plotyy",
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
155 "visible", "off", "handlevisibility", "off",
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10529
diff changeset
156 "xliminclude", "off", "yliminclude", "off");
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
157
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
158 set (t1, "deletefcn", {@deleteplotyy, ax(2), t2});
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
159 set (t2, "deletefcn", {@deleteplotyy, ax(1), t1});
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
160
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
161 ## Add cross-listeners so a change in one axes' attributes updates the other.
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
162 addlistener (ax(1), "position", {@update_position, ax(2)});
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
163 addlistener (ax(2), "position", {@update_position, ax(1)});
12685
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
164 addlistener (ax(1), "outerposition", {@update_position, ax(2)});
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
165 addlistener (ax(2), "outerposition", {@update_position, ax(1)});
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
166 addlistener (ax(1), "looseinset", {@update_position, ax(2)});
5cbf660e649d Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents: 12575
diff changeset
167 addlistener (ax(2), "looseinset", {@update_position, ax(1)});
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
168 addlistener (ax(1), "view", {@update_position, ax(2)});
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
169 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
170 addlistener (ax(1), "plotboxaspectratio", {@update_position, ax(2)});
2884758e265b Replace dataaspectratio props with plotboxaspectratio props.
Ben Abbott <bpabbott@mac.com>
parents: 10136
diff changeset
171 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
172 addlistener (ax(1), "plotboxaspectratiomode", {@update_position, ax(2)});
7147078550fe plotyy.m: Add listener for dataaspectratiomode.
Ben Abbott <bpabbott@mac.com>
parents: 10226
diff changeset
173 addlistener (ax(2), "plotboxaspectratiomode", {@update_position, ax(1)});
14780
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
174 addlistener (ax(1), "nextplot", {@update_nextplot, ax(2)});
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
175 addlistener (ax(2), "nextplot", {@update_nextplot, ax(1)});
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
176
9349
93664cbb732c plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents: 9346
diff changeset
177 ## Store the axes handles for the sister axes.
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13130
diff changeset
178 if (ishandle (ax(1)) && ! isprop (ax(1), "__plotyy_axes__"))
10950
c9786e03670c Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents: 10949
diff changeset
179 addproperty ("__plotyy_axes__", ax(1), "data", ax);
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13130
diff changeset
180 elseif (ishandle (ax(1)))
10950
c9786e03670c Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents: 10949
diff changeset
181 set (ax(1), "__plotyy_axes__", ax);
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13130
diff changeset
182 else
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14868
diff changeset
183 error ("plotyy.m: This shouldn't happen. File a bug report.");
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13130
diff changeset
184 endif
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13130
diff changeset
185 if (ishandle (ax(2)) && ! isprop (ax(2), "__plotyy_axes__"))
10950
c9786e03670c Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents: 10949
diff changeset
186 addproperty ("__plotyy_axes__", ax(2), "data", ax);
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13130
diff changeset
187 elseif (ishandle (ax(2)))
10950
c9786e03670c Don't create __plotyy_axes__ properties in plotyy if they exist (Bug #30977)
David Bateman <dbateman@free.fr>
parents: 10949
diff changeset
188 set (ax(2), "__plotyy_axes__", ax);
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13130
diff changeset
189 else
15202
f3b5cadfd6d5 fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents: 14868
diff changeset
190 error ("plotyy.m: This shouldn't happen. File a bug report.");
13216
434e227b100b Improvements to plotyy.
Ben Abbott <bpabbott@mac.com>
parents: 13130
diff changeset
191 endif
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
192 endfunction
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
193
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
194 function deleteplotyy (h, ~, ax2, t2)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
195 if (isaxes (ax2)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
196 && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
197 && strcmp (get (ax2, "beingdeleted"), "off"))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
198 set (t2, "deletefcn", []);
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
199 delete (ax2);
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
200 endif
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
201 endfunction
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
202
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
203 function update_nextplot (h, ~, ax2)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
204 persistent recursion = false;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
205 if (! recursion)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
206 unwind_protect
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
207 recursion = true;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
208 set (ax2, "nextplot", get (h, "nextplot"));
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
209 unwind_protect_cleanup
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
210 recursion = false;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
211 end_unwind_protect
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
212 endif
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
213 endfunction
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
214
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
215 function update_position (h, ~, ax2)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
216 persistent recursion = false;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
217
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
218 ## Don't allow recursion
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
219 if (! recursion)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
220 unwind_protect
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
221 recursion = true;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
222 view = get (h, "view");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
223 oldview = get (ax2, "view");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
224 plotboxaspectratio = get (h, "plotboxaspectratio");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
225 oldplotboxaspectratio = get (ax2, "plotboxaspectratio");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
226 plotboxaspectratiomode = get (h, "plotboxaspectratiomode");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
227 oldplotboxaspectratiomode = get (ax2, "plotboxaspectratiomode");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
228
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
229 if (strcmp (get (h, "activepositionproperty"), "position"))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
230 position = get (h, "position");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
231 oldposition = get (ax2, "position");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
232 if (! (isequal (position, oldposition) && isequal (view, oldview)))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
233 set (ax2, "position", position, "view", view);
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
234 endif
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
235 else
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
236 outerposition = get (h, "outerposition");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
237 oldouterposition = get (ax2, "outerposition");
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
238 if (! (isequal (outerposition, oldouterposition)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
239 && isequal (view, oldview)))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
240 set (ax2, "outerposition", outerposition, "view", view);
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
241 endif
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
242 endif
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
243
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
244 if (! (isequal (plotboxaspectratio, oldplotboxaspectratio)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
245 && isequal (plotboxaspectratiomode, oldplotboxaspectratiomode)))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
246 set (ax2, "plotboxaspectratio", plotboxaspectratio,
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
247 "plotboxaspectratiomode", plotboxaspectratiomode);
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
248 endif
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
249 unwind_protect_cleanup
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
250 recursion = false;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
251 end_unwind_protect
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
252 endif
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
253 endfunction
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
254
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
255 function color = getcolor (ax)
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
256 obj = get (ax);
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
257 if (isfield (obj, "color"))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
258 color = obj.color;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
259 elseif (isfield (obj, "facecolor") && ! ischar (obj.facecolor))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
260 color = obj.facecolor;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
261 elseif (isfield (obj, "edgecolor") && ! ischar (obj.edgecolor))
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
262 color = obj.edgecolor;
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
263 else
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
264 color = [0, 0, 0];
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
265 endif
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
266 endfunction
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
267
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
268
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
269 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
270 %! clf;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
271 %! x = 0:0.1:2*pi;
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
272 %! y1 = sin (x);
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
273 %! y2 = exp (x - 1);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
274 %! ax = plotyy (x,y1, x-1,y2, @plot, @semilogy);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
275 %! xlabel ('X');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
276 %! ylabel (ax(1), 'Axis 1');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
277 %! ylabel (ax(2), 'Axis 2');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
278 %! text (0.5, 0.5, 'Left Axis', ...
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
279 %! 'color', [0 0 1], 'horizontalalignment', 'center', 'parent', ax(1));
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
280 %! text (4.5, 80, 'Right Axis', ...
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
281 %! 'color', [0 0.5 0], 'horizontalalignment', 'center', 'parent', ax(2));
18910
cafffc1b70b1 update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18344
diff changeset
282 %! title ({'plotyy() example'; 'Left axis uses @plot, Right axis uses @semilogy'});
8208
f6ca8ff51818 [mq]: graphics-backend
John W. Eaton <jwe@octave.org>
parents: 8102
diff changeset
283
9349
93664cbb732c plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents: 9346
diff changeset
284 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
285 %! clf;
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14245
diff changeset
286 %! colormap ('default');
9349
93664cbb732c plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents: 9346
diff changeset
287 %! x = linspace (-1, 1, 201);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
288 %! subplot (2,2,1);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
289 %! plotyy (x,sin(pi*x), x,10*cos(pi*x));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
290 %! subplot (2,2,2);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
291 %! surf (peaks (25));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
292 %! subplot (2,2,3);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
293 %! contour (peaks (25));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
294 %! subplot (2,2,4);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
295 %! plotyy (x,10*sin(2*pi*x), x,cos(2*pi*x));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
296 %! axis square;
9349
93664cbb732c plotyy.m: Fix compatibility with subplot.
Ben Abbott <bpabbott@mac.com>
parents: 9346
diff changeset
297
13033
d0dccc6dd4e7 plotyy.m: Always restore current axes when done.
Ben Abbott <bpabbott@mac.com>
parents: 12575
diff changeset
298 %!demo
14780
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
299 %! clf
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
300 %! hold on
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
301 %! t = (0:0.1:9);
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
302 %! x = sin (t);
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
303 %! y = 5 * cos (t);
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
304 %! [hax, h1, h2] = plotyy (t, x, t, y);
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
305 %! [~, h3, h4] = plotyy (t+1, x, t+1, y);
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16814
diff changeset
306 %! set ([h3, h4], 'linestyle', '--');
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16814
diff changeset
307 %! xlabel (hax(1), 'xlabel');
18344
097202cbe564 plotyy.m: Overhaul function to use updated newplot().
Rik <rik@octave.org>
parents: 17744
diff changeset
308 %! title (hax(2), 'Two plotyy graphs on same figure using "hold on"');
16828
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16814
diff changeset
309 %! ylabel (hax(1), 'Left axis is Blue');
ddac88d32d6a Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents: 16814
diff changeset
310 %! ylabel (hax(2), 'Right axis is Green');
14780
1d83d1539b2b Fix plotyy to function as expected with "hold on" (Bug # 36508)
Ben Abbott <bpabbott@mac.com>
parents: 14363
diff changeset
311