comparison scripts/plot/plotyy.m @ 9349:93664cbb732c

plotyy.m: Fix compatibility with subplot.
author Ben Abbott <bpabbott@mac.com>
date Sun, 14 Jun 2009 20:33:47 -0400
parents d50c3d8efe71
children 335dc62068a8
comparison
equal deleted inserted replaced
9348:44377339a398 9349:93664cbb732c
73 else 73 else
74 f = get (0, "currentfigure"); 74 f = get (0, "currentfigure");
75 if (isempty (f)) 75 if (isempty (f))
76 f = figure (); 76 f = figure ();
77 endif 77 endif
78 ax = get (f, "children"); 78 ca = get (f, "currentaxes");
79 if (isempty (ca))
80 ax = [];
81 elseif (strcmp (get (ca, "tag"), "plotyy"));
82 ax = get (ca, "__plotyy_axes__");
83 else
84 ax = ca;
85 endif
79 if (length (ax) > 2) 86 if (length (ax) > 2)
80 for i = 3 : length (ax) 87 for i = 3 : length (ax)
81 delete (ax (i)); 88 delete (ax (i));
82 endfor 89 endfor
83 ax = ax(1:2); 90 ax = ax(1:2);
173 180
174 addlistener (ax(1), "position", {@update_position, ax(2)}); 181 addlistener (ax(1), "position", {@update_position, ax(2)});
175 addlistener (ax(2), "position", {@update_position, ax(1)}); 182 addlistener (ax(2), "position", {@update_position, ax(1)});
176 addlistener (ax(1), "view", {@update_position, ax(2)}); 183 addlistener (ax(1), "view", {@update_position, ax(2)});
177 addlistener (ax(2), "view", {@update_position, ax(1)}); 184 addlistener (ax(2), "view", {@update_position, ax(1)});
185 addlistener (ax(1), "dataaspectratio", {@update_position, ax(2)});
186 addlistener (ax(2), "dataaspectratio", {@update_position, ax(1)});
178 187
179 ## Tag the plotyy axes, so we can use that information 188 ## Tag the plotyy axes, so we can use that information
180 ## not to mirror the y axis tick marks 189 ## not to mirror the y axis tick marks
181 set (ax, "tag", "plotyy") 190 set (ax, "tag", "plotyy")
191
192 ## Store the axes handles for the sister axes.
193 addproperty ("__plotyy_axes__", ax(1), "data", ax);
194 addproperty ("__plotyy_axes__", ax(2), "data", ax);
182 195
183 endfunction 196 endfunction
184 197
185 %!demo 198 %!demo
186 %! clf 199 %! clf
190 %! ax = plotyy (x, y1, x - 1, y2, @plot, @semilogy); 203 %! ax = plotyy (x, y1, x - 1, y2, @plot, @semilogy);
191 %! xlabel ("X"); 204 %! xlabel ("X");
192 %! ylabel (ax(1), "Axis 1"); 205 %! ylabel (ax(1), "Axis 1");
193 %! ylabel (ax(2), "Axis 2"); 206 %! ylabel (ax(2), "Axis 2");
194 207
208 %!demo
209 %! clf
210 %! x = linspace (-1, 1, 201);
211 %! subplot (2, 2, 1)
212 %! plotyy (x, sin(pi*x), x, 10*cos(pi*x))
213 %! subplot (2, 2, 2)
214 %! surf (peaks (25))
215 %! subplot (2, 2, 3)
216 %! contour (peaks (25))
217 %! subplot (2, 2, 4)
218 %! plotyy (x, 10*sin(2*pi*x), x, cos(2*pi*x))
219 %! axis square
220
195 function deleteplotyy (h, d, ax2, t2) 221 function deleteplotyy (h, d, ax2, t2)
196 if (ishandle (ax2) && strcmp (get (ax2, "type"), "axes") && 222 if (ishandle (ax2) && strcmp (get (ax2, "type"), "axes") &&
197 (isempty (gcbf()) || strcmp (get (gcbf(), "beingdeleted"),"off")) && 223 (isempty (gcbf()) || strcmp (get (gcbf(), "beingdeleted"),"off")) &&
198 strcmp (get (ax2, "beingdeleted"), "off")) 224 strcmp (get (ax2, "beingdeleted"), "off"))
199 set (t2, "deletefcn", []); 225 set (t2, "deletefcn", []);
208 if (! recursion) 234 if (! recursion)
209 unwind_protect 235 unwind_protect
210 recursion = true; 236 recursion = true;
211 position = get (h, "position"); 237 position = get (h, "position");
212 view = get (h, "view"); 238 view = get (h, "view");
239 dataaspectratio = get (h, "dataaspectratio");
213 oldposition = get (ax2, "position"); 240 oldposition = get (ax2, "position");
214 oldview = get (ax2, "view"); 241 oldview = get (ax2, "view");
215 if (! (isequal (position, oldposition) && isequal (view, oldview))) 242 olddataaspectratio = get (ax2, "dataaspectratio");
216 set (ax2, "position", position, "view", view); 243 if (! (isequal (position, oldposition)
244 && isequal (view, oldview)
245 && isequal (dataaspectratio, olddataaspectratio)))
246 set (ax2, "position", position,
247 "view", view,
248 "dataaspectratio", dataaspectratio);
217 endif 249 endif
218 unwind_protect_cleanup 250 unwind_protect_cleanup
219 recursion = false; 251 recursion = false;
220 end_unwind_protect 252 end_unwind_protect
221 endif 253 endif