【Matlab】 如何在一张图上画多个坐标轴
(2012-08-23 14:01:59)
标签:
杂谈 |
分类: MATLAB |
原帖:http://www.matlabsky.com/thread-11209-1-1.html
文件交流上好像有画3y轴的函数:
function [ax,hlines] = plotyyy(x1,y1,x2,y2,x3,y3,ylabels)%PLOTYYY - Extends plotyy to include a third y-axis
%Syntax:
%Inputs: x1,y1 are the xdata and ydata for the first axes' line
%
%
%
%Outputs: ax -
%
%Author: Denis Gilbert, Ph.D., physical oceanography
%Maurice Lamontagne Institute
�pt. of Fisheries and Oceans Canada
%email:
%Web:
%April 2000; Last revision: 14-Nov-2001
if nargin==6
elseif nargin > 7
elseif nargin < 6
end
figure('units','normalized',...
[ax,hlines(1),hlines(2)] = plotyy(x1,y1,x2,y2);
cfig = get(gcf,'color');
pos = [0.1
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)
ax(3)=axes('Position',pos3,'box','off',...
hlines(3) = line(x3,y3,'Color','r','Parent',ax(3));
limy3=get(ax(3),'YLim');
line([limx1(2) limx3(2)],[limy3(1) limy3(1)],...
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})
% 例子
% x = [0 0.1 0.2 0.3 0.4 0.426 0.5 0.6 0.688 0.7 0.8 0.9 1.0];
% y = [268.95 272.36 275.07 277.07 277.93 278 276.5 267.16 248.2 244.3 200.37 137.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.873 0.6];
% ylabels{1}='轴1';
% ylabels{2}='轴2';
% ylabels{3}='轴3';
% [ax,hlines] = plotyyy(x,y,x,a,x,k,ylabels);
% legend(hlines, 'y = x','a =x','k = x',2)