Functions | |
if (strcmp(obj1.type,"axes")||strcmp(obj2.type,"axes")) ax | |
varargin (1) | |
if (isempty(varargin)) varargin | |
endif else | error ("plotyy: expecting first argument to be axes handle") |
if (isempty(f)) f | |
if (isempty(ca)) ax | |
elseif (strcmp(get(ca,"tag"),"plotyy")) | |
endif | if (length(ax) > 2) for i |
elseif (length(ax)==1) ax(2) | |
elseif (isempty(ax)) ax(1) | |
ax (2) | |
endif | if (nargin< 2) varargin |
unwind_protect_cleanup | if (ishandle(oldh)&&strcmp(get(oldh,"type"),"axes")) axes(oldh) |
endif end_unwind_protect | if (nargout > 0) Ax |
endif | if (nargin > 6) fun2 |
if (ishandle(ax(1))&&strcmp(get(ax(1),"type"),"axes")) axes(ax(1)) | |
else | ax (1) |
endif | newplot () |
set (ax(1),"ycolor", getcolor(h1(1))) | |
set (ax(1),"xlim", xlim) | |
set (cf,"nextplot","add") | |
if (ishandle(ax(2))&&strcmp(get(ax(2),"type"),"axes")) axes(ax(2)) | |
set (ax(2),"colororder",[colors(2:end,:);colors(1,:)]) | |
set (ax(2),"yaxislocation","right") | |
set (ax(2),"ycolor", getcolor(h2(1))) | |
set (ax(2),"position", get(ax(1),"position")) | |
set (ax(2),"xlim", xlim) | |
set (ax(2),"color","none") | |
set (t1,"deletefcn",{@deleteplotyy, ax(2), t2}) | |
set (t2,"deletefcn",{@deleteplotyy, ax(1), t1}) | |
addlistener (ax(1),"position",{@update_position, ax(2)}) | |
addlistener (ax(2),"position",{@update_position, ax(1)}) | |
addlistener (ax(1),"view",{@update_position, ax(2)}) | |
addlistener (ax(2),"view",{@update_position, ax(1)}) | |
addlistener (ax(1),"dataaspectratio",{@update_position, ax(2)}) | |
addlistener (ax(2),"dataaspectratio",{@update_position, ax(1)}) | |
set (ax,"tag","plotyy") addproperty("__plotyy_axes__" | |
addproperty ("__plotyy_axes__", ax(2),"data", ax) | |
!xlabel ("X") | |
!ylabel (ax(1),"Axis 1") | |
!ylabel (ax(2),"Axis 2") | |
!subplot (2, 2, 1)%!plotyy(x | |
sin (pi *x) | |
* | cos (pi *x))%!subplot(2 |
!surf (peaks(25))%!subplot(2 | |
!contour (peaks(25))%!subplot(2 | |
!plotyy (x, 10 *sin(2 *pi *x), x, cos(2 *pi *x))%!axis square function deleteplotyy(h | |
t2 | if (ishandle(ax2)&&strcmp(get(ax2,"type"),"axes")&&(isempty(gcbf())||strcmp(get(gcbf(),"beingdeleted"),"off"))&&strcmp(get(ax2,"beingdeleted"),"off")) set(t2 |
t2 | delete (ax2) |
endif endfunction function | update_position (h, d, ax2) persistent recursion |
if (!recursion) unwind_protect recursion | |
if (!(isequal(position, oldposition)&&isequal(view, oldview))) set(ax2 | |
view endif | if (!(isequal(dataaspectratio, olddataaspectratio)&&isequal(dataaspectratiomode, olddataaspectratiomode))) set(ax2 |
set (ax2,"dataaspectratiomode", dataaspectratiomode) | |
if (isfield(obj,"color")) color | |
elseif (isfield(obj,"facecolor")&&!ischar(obj.facecolor)) color | |
elseif (isfield(obj,"edgecolor")&&!ischar(obj.edgecolor)) color | |
Variables | |
function [Ax, H1, H2] | |
obj2 = get (varargin{1}(2)) | |
endif else | f = get (0, "currentfigure") |
endif | ca = get (f, "currentaxes") |
ax = get (ca, "__plotyy_axes__") | |
endif | oldh = gca () |
unwind_protect [ax, h1, h2] = __plotyy__ (ax, varargin{:}) | |
H1 = h1 | |
H2 = h2 | |
else | fun1 = @plot |
else | fun2 = fun1 |
endif | xlim = [min([x1(:); x2(:)]), max([x1(:); x2(:)])] |
h1 = feval (fun1, x1, y1) | |
cf = gcf () | |
colors = get (ax(1), "colororder") | |
h2 = feval (fun2, x2, y2) | |
t1 | |
t2 | |
data | |
endfunction!demo!clf | !x = 0:0.1:2*pi |
!y1 = sin (x) | |
!y2 = exp (x - 1) | |
!ax = plotyy (x, y1, x - 1, y2, @plot, @semilogy) | |
x | |
d | |
ax2 | |
t2 | deletefcn |
position = get (h, "position") | |
view = get (h, "view") | |
dataaspectratio = get (h, "dataaspectratio") | |
dataaspectratiomode = get (h, "dataaspectratiomode") | |
oldposition = get (ax2, "position") | |
oldview = get (ax2, "view") | |
olddataaspectratio = get (ax2, "dataaspectratio") | |
olddataaspectratiomode = get (ax2, "dataaspectratiomode") | |
endif unwind_protect_cleanup | recursion = false |
end_unwind_protect endif endfunction function | color |
!contour | ( | peaks(25) | ) |
!plotyy | ( | x | , | |
10 * | sin2 *pi *x, | |||
x | , | |||
cos(2 *pi *x) | ||||
) |
!subplot | ( | 2 | , | |
2 | , | |||
1 | ||||
) |
!surf | ( | peaks(25) | ) |
!xlabel | ( | "X" | ) |
!ylabel | ( | ax(2) | , | |
"Axis 2" | ||||
) |
!ylabel | ( | ax(1) | , | |
"Axis 1" | ||||
) |
addlistener | ( | ax(2) | , | |
"dataaspectratio" | ||||
) |
addlistener | ( | ax(1) | , | |
"dataaspectratio" | ||||
) |
addlistener | ( | ax(2) | , | |
"view" | ||||
) |
addlistener | ( | ax(1) | , | |
"view" | ||||
) |
addlistener | ( | ax(2) | , | |
"position" | ||||
) |
addlistener | ( | ax(1) | , | |
"position" | ||||
) |
addproperty | ( | "__plotyy_axes__" | , | |
ax(2) | , | |||
"data" | , | |||
ax | ||||
) |
else ax | ( | 1 | ) |
ax | ( | 2 | ) |
* cos | ( | pi * | x | ) |
elseif | ( | isfield(obj,"edgecolor")&&!ischar(obj.edgecolor) | ) |
elseif | ( | isfield(obj,"facecolor")&&!ischar(obj.facecolor) | ) |
elseif | ( | isempty(ax) | ) |
elseif | ( | length(ax) | = =1 |
) |
elseif | ( | strcmp(get(ca,"tag"),"plotyy") | ) |
if | ( | isfield(obj,"color") | ) |
view endif if | ( | ! | isequal(dataaspectratio, olddataaspectratio)&&isequal(dataaspectratiomode, olddataaspectratiomode) | ) |
if | ( | ! | isequal(position, oldposition)&&isequal(view, oldview) | ) |
if | ( | ! | recursion | ) |
t2 if | ( | ishandle(ax2)&&strcmp(get(ax2,"type"),"axes")&&(isempty(gcbf())||strcmp(get(gcbf(),"beingdeleted"),"off"))&&strcmp(get(ax2,"beingdeleted"),"off") | ) |
if | ( | ishandle(ax(2))&&strcmp(get(ax(2),"type"),"axes") | ) |
if | ( | ishandle(ax(1))&&strcmp(get(ax(1),"type"),"axes") | ) |
endif end_unwind_protect if | ( | nargout | , | |
0 | ||||
) |
endif if | ( | ) |
endif if | ( | length(ax) | , | |
2 | ||||
) |
if | ( | isempty(ca) | ) |
if | ( | isempty(f) | ) |
if | ( | isempty(varargin) | ) |
endif newplot | ( | ) |
set | ( | ax2 | , | |
"dataaspectratiomode" | , | |||
dataaspectratiomode | ||||
) |
set | ( | ax | , | |
"tag" | , | |||
"plotyy" | ||||
) |
set | ( | t2 | , | |
"deletefcn" | ||||
) |
set | ( | t1 | , | |
"deletefcn" | ||||
) |
set | ( | ax(2) | , | |
"color" | , | |||
"none" | ||||
) |
set | ( | ax(2) | , | |
"xlim" | , | |||
xlim | ||||
) |
set | ( | ax(2) | , | |
"position" | , | |||
get(ax(1),"position") | ||||
) |
set | ( | ax(2) | , | |
"ycolor" | , | |||
getcolor(h2(1)) | ||||
) |
set | ( | ax(2) | , | |
"yaxislocation" | , | |||
"right" | ||||
) |
set | ( | ax(2) | , | |
"colororder" | ||||
) |
set | ( | cf | , | |
"nextplot" | , | |||
"add" | ||||
) |
set | ( | ax(1) | , | |
"xlim" | , | |||
xlim | ||||
) |
set | ( | ax(1) | , | |
"ycolor" | , | |||
getcolor(h1(1)) | ||||
) |
sin | ( | pi * | x | ) |
endif endfunction function update_position | ( | h | , | |
d | , | |||
ax2 | ||||
) |
varargin | ( | 1 | ) |
!demo ! clf !x = 0:0.1:2*pi |
!y1 = sin (x) |
!y2 = exp (x - 1) |
ax = get (ca, "__plotyy_axes__") |
cf = gcf () |
colors = get (ax(1), "colororder") |
d |
view endif dataaspectratio = get (h, "dataaspectratio") |
dataaspectratiomode = get (h, "dataaspectratiomode") |
endif endfunction function[ax, h1, h2] |
H2 = h2 |
obj2 = get (varargin{1}(2)) |
olddataaspectratio = get (ax2, "dataaspectratio") |
olddataaspectratiomode = get (ax2, "dataaspectratiomode") |
oldposition = get (ax2, "position") |
position = get (h, "position") |
demo clf t1 |
unwind_protect[ax, h1, h2] = __plotyy__ (ax, varargin{:}) |
view = get (h, "view") |
x |