【转】MATLAB:双X轴曲线绘图

标签:
matlabit |
分类: MATLAB |
在MATLAB中没有提供函数 绘制双X轴曲线,不过可以从以下网址下载得到:http://www.mathworks.com/matlabcentral/fx_files/317/1/plotxx.zip
该函数调用格式为:
[ax,hl1,hl2] = plotxx(x1,y1,x2,y2,xlabels,ylabels);
参数说明:
ax是坐标轴的句柄。h1 和 h2 是两条曲线的句柄。x1,y1,x2,y2 是绘图数据。Xlabels,Ylabels是X轴和Y州标注内容对应的细胞结构。
例:
D = linspace(-100,0,50);%Y轴数据
S = linspace(34,32,50);%上侧X轴数据
T = 10*exp(D/40);%下侧X轴数据
xlabels{1} = 'Temperature (C)';%下侧X轴内容标注
xlabels{2} = 'Salinity';%上侧X轴内容标注
ylabels{1} = 'Depth(m)';%左侧Y轴内容标注
ylabels{2} = 'Depth(m)';%右侧Y轴内容标注
[ax,hlT,hlS] = plotxx(T,D,S,D,xlabels,ylabels);%绘制双X轴曲线
http://hiphotos.baidu.com/lb%CD%BC%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD/pic/item/22824e5080a78b11d00906bc.jpg
附件:plotxx.m
function [ax,hl1,hl2] = plotxx(x1,y1,x2,y2,xlabels,ylabels);
%PLOTXX - Create graphs with x axes on both top and
bottom
%
%Similar to PLOTYY, but ...
%the independent variable is on the y-axis,
%and both dependent variables are on the x-axis.
%
%Syntax: [ax,hl1,hl2] = plotxx(x1,y1,x2,y2,xlabels,ylabels);
%
%Inputs: X1,Y1 are the data for the first line (black)
%
%
%
%
%The optional output handle graphics objects AX,HL1,HL2
%allow the user to easily change the properties of the plot.
%
%Example: Plot temperature T and salinity S
%
%
%D = linspace(-100,0,50);
%S = linspace(34,32,50);
%T = 10*exp(D/40);
%xlabels{1} = 'Temperature (C)';
%xlabels{2} = 'Salinity';
%ylabels{1} = 'Depth(m)';
%ylabels{2} = 'Depth(m)';
%[ax,hlT,hlS] = plotxx(T,D,S,D,xlabels,ylabels);
%The code is inspired from page 10-26 (Multiaxis axes)
%of the manual USING MATLAB GRAPHICS, version 5.
%
%Tested with Matlab 5.3.1 and above on PCWIN
%Author: Denis Gilbert, Ph.D., physical oceanography
%Maurice Lamontagne Institute, Dept. of Fisheries and Oceans
Canada
%email: Web:
%November 1997; Last revision: 01-Nov-2001
if nargin < 4
elseif nargin==4
elseif nargin==5
elseif nargin > 6
end
if length(ylabels) == 1
end
if ~iscellstr(xlabels)
elseif ~iscellstr(ylabels)
end
hl1=line(x1,y1,'Color','k');
ax(1)=gca;
set(ax(1),'Position',[0.12 0.12 0.75 0.70])
set(ax(1),'XColor','k','YColor','k');
ax(2)=axes('Position',get(ax(1),'Position'),...
set(ax,'box','off')
hl2=line(x2,y2,'Color','r','Parent',ax(2));
%label the two x-axes
set(get(ax(1),'xlabel'),'string',xlabels{1})
set(get(ax(2),'xlabel'),'string',xlabels{2})
set(get(ax(1),'ylabel'),'string',ylabels{1})
set(get(ax(2),'ylabel'),'string',ylabels{2})