Source: Http://wenku.baidu.com/link?url=m_eEkzbjnT9ccgAnlPVDqHCVyrZOD2EplXxxIiQc69DI0lHAWzwpZXfdDy_ 7dpbwixc4t6c1zi9wfi5dlf6hetc1mc69fjaapstpiic_hbe
Code:
function [Ax,hlines] = plotyyy (x1,y1,x2,y2,x3,y3,ylabels)
%plotyyy-extends Plotyy to include a third y-axis
%syntax: [Ax,hlines] = plotyyy (x1,y1,x2,y2,x3,y3,ylabels)
%inputs:x1,y1 is the XData and ydata for the first axes ' line
% X2,y2 is the xdata and ydata for thesecond axes ' line
% X3,y3 is the xdata and ydata for Thethird axes ' line
% ylabels is a 3x1 cell array containingthe ylabel strings
%OUTPUTS:AX-3X1 double array containing the axes ' handles
% hlines-3x1 Double array containingthe lines ' handles
%author:denis Gilbert, Ph.D., Physical oceanography
%maurice LaMontagne Institute
%dept. of fisheries and Oceans Canada
%email: [Email protected]
%web:http://www.qc.dfo-mpo.gc.ca/iml/
%april 2000; Last revision:14-nov-2001
If nargin==6
Ylabels{1}= "; Ylabels{2}= "; Ylabels{3}= ";
ElseIf Nargin > 7
Error (' Too many input arguments ')
ElseIf Nargin < 6
Error (' Not enough input arguments ')
End
Figure (' units ', ' normalized ',...
' Defaultaxesxminortick ', ' on ', ' Defaultaxesyminortick ', ' on ');
[Ax,hlines (1), Hlines (2)] = Plotyy (x1,y1,x2,y2);
Cfig = Get (GCF, ' color ');
pos = [0.1 0.1 0.7 0.8];
Offset = pos (3)/5.5;
POS (3) = pos (3)-OFFSET/2;
Set (ax, ' position ', POS);
Pos3=[pos (1) POS (2) POS (3) +offset POS (4)];
Limx1=get (Ax (1), ' Xlim ');
LIMX3=[LIMX1 (1) limx1 (1) + 1.2* (LIMX1 (2)-limx1 (1))];
Ax (3) =axes (' Position ', pos3, ' box ', ' Off ',...
' Color ', ' none ', ' xcolor ', ' k ', ' Ycolor ', ' R ',...
' XTick ', [], ' Xlim ', limx3, ' yaxislocation ', ' right ');
Hlines (3) = line (X3,y3, ' Color ', ' r ', ' Parent ', ax (3));
Limy3=get (Ax (3), ' Ylim ');
Line ([Limx1 (2) limx3 (2)],[limy3 (1) limy3 (1)],...
' Color ', Cfig, ' Parent ', ax (3), ' Clipping ', ' off ');
Axes (ax (2))
Set (Get (Ax (1), ' Ylabel '), ' string ', ylabels{1})
Set (Get (Ax (2), ' Ylabel '), ' string ', ylabels{2})
Set (Get (Ax (3), ' Ylabel '), ' string ', ylabels{3})
Instance:
Run in Commond window:
Code:
x = [0 0.1 0.2 0.3 0.4 0.426 0.5 0.6 0.688 0.7 0.8 0.91.0];
y = [268.95 272.36 275.07 277.07 277.93 278 276.5 267.16 248.2 244.3 200.37137.71 58.7];
A = [0 0.225 0.408 0.566 0.693 0.718 0.776 0.82 0.831 0.831 0.818 0.784 0.6];
K = [2.55 2.254 2.063 1.886 1.733 1.687 1.552 1.368 1.207 1.187 1.023 0.8730.6];
ylabels{1}= ' Axis 1 ';
ylabels{2}= ' Axis 2 ';
Ylabels{3}= ' Axis 3 ';
[Ax,hlines] = plotyyy (x,y,x,a,x,k,ylabels);
Legend (hlines, ' y = X ', ' A =x ', ' k = X ', 2)
"Go" matlab add multiple vertical axes to a picture