Mercurial > hg > octave-lyh
comparison scripts/plot/plotyy.m @ 7665:aead4b9d026b
Fix axis handle treatment in plotyy
author | David Bateman <dbateman@free.fr> |
---|---|
date | Fri, 28 Mar 2008 12:52:31 -0400 |
parents | 8e5feea0545a |
children | 86955a1559c5 |
comparison
equal
deleted
inserted
replaced
7664:0dff8d9bf229 | 7665:aead4b9d026b |
---|---|
53 ## @end example | 53 ## @end example |
54 ## @end deftypefn | 54 ## @end deftypefn |
55 | 55 |
56 function [Ax, H1, H2] = plotyy (varargin) | 56 function [Ax, H1, H2] = plotyy (varargin) |
57 | 57 |
58 [ax, varargin] = __plt_get_axis_arg__ ("plotyy", varargin{:}); | 58 ## Don't use __plt_get_axis_arg__ here as ax is a two vector for plotyy |
59 if (nargin > 1 && length (varargin{1}) == 2 && ishandle(varargin{1}(1)) | |
60 && ishandle(varargin{1}(2)) && | |
61 all (floor (varargin{1}) != varargin{1})) | |
62 obj1 = get (varargin{1}(1)); | |
63 obj2 = get (varargin{1}(2)); | |
64 if (strcmp (obj1.type, "axes") || strcmp (obj2.type, "axes")) | |
65 ax = [obj1, obj2]; | |
66 varargin(1) = []; | |
67 if (isempty (varargin)) | |
68 varargin = {}; | |
69 endif | |
70 else | |
71 error ("plotyy: expecting first argument to be axes handle"); | |
72 endif | |
73 else | |
74 f = get (0, "currentfigure"); | |
75 if (isempty (f)) | |
76 ax(1) = axes (); | |
77 ax(2) = axes (); | |
78 else | |
79 ax = get (f, "children"); | |
80 for i = 3 : length (ax) | |
81 delete (ax (i)); | |
82 endfor | |
83 ax = ax(1:2); | |
84 endif | |
85 if (nargin < 2) | |
86 varargin = {}; | |
87 endif | |
88 endif | |
59 | 89 |
60 if (nargin < 4) | 90 if (nargin < 4) |
61 print_usage (); | 91 print_usage (); |
62 endif | 92 endif |
63 | 93 |
64 oldh = gca (); | 94 oldh = gca (); |
65 unwind_protect | 95 unwind_protect |
66 axes (ax); | |
67 newplot (); | |
68 [ax, h1, h2] = __plotyy__ (ax, varargin{:}); | 96 [ax, h1, h2] = __plotyy__ (ax, varargin{:}); |
69 unwind_protect_cleanup | 97 unwind_protect_cleanup |
70 axes (oldh); | 98 axes (oldh); |
71 end_unwind_protect | 99 end_unwind_protect |
72 | 100 |
90 fun2 = fun1; | 118 fun2 = fun1; |
91 endif | 119 endif |
92 | 120 |
93 xlim = [min([x1(:); x2(:)]), max([x1(:); x2(:)])]; | 121 xlim = [min([x1(:); x2(:)]), max([x1(:); x2(:)])]; |
94 | 122 |
123 axes (ax(1)); | |
124 newplot (); | |
95 h1 = feval (fun1, x1, y1); | 125 h1 = feval (fun1, x1, y1); |
96 | 126 |
97 set (ax(1), "ycolor", getcolor (h1(1))); | 127 set (ax(1), "ycolor", getcolor (h1(1))); |
98 set (ax(1), "position", [0.11 0.13 0.78 0.73]); | 128 set (ax(1), "position", [0.11 0.13 0.78 0.73]); |
99 set (ax(1), "activepositionproperty", "position"); | 129 set (ax(1), "activepositionproperty", "position"); |
100 set (ax(1), "xlim", xlim); | 130 set (ax(1), "xlim", xlim); |
101 | 131 |
102 cf = gcf (); | 132 cf = gcf (); |
103 set (cf, "nextplot", "add"); | 133 set (cf, "nextplot", "add"); |
104 ax(2) = axes (); | 134 axes (ax(2)); |
135 newplot (); | |
136 | |
105 colors = get (ax(1), "colororder"); | 137 colors = get (ax(1), "colororder"); |
106 set (ax(2), "colororder", [colors(2:end,:); colors(1,:)]); | 138 set (ax(2), "colororder", [colors(2:end,:); colors(1,:)]); |
107 | 139 |
108 h2 = feval (fun2, x2, y2); | 140 h2 = feval (fun2, x2, y2); |
109 set (ax(2), "yaxislocation", "right"); | 141 set (ax(2), "yaxislocation", "right"); |