Home > atmlab > graphs > plotxx.m

plotxx

PURPOSE ^

PLOTXX - Create graphs with x axes on both top and bottom

SYNOPSIS ^

function [ax,hl1,hl2] = plotxx(x1,y1,x2,y2,xlabels,ylabels);

DESCRIPTION ^

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)
         X2,Y2 are the data for the second line (red)
         XLABELS is a cell array containing the two x-labels
         YLABELS is a cell array containing the two y-labels

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 
         as a function of depth D in the ocean

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);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

plotxx.m

SOURCE CODE ^

0001 function [ax,hl1,hl2] = plotxx(x1,y1,x2,y2,xlabels,ylabels);
0002 %PLOTXX - Create graphs with x axes on both top and bottom
0003 %
0004 %Similar to PLOTYY, but ...
0005 %the independent variable is on the y-axis,
0006 %and both dependent variables are on the x-axis.
0007 %
0008 %Syntax: [ax,hl1,hl2] = plotxx(x1,y1,x2,y2,xlabels,ylabels);
0009 %
0010 %Inputs:  X1,Y1 are the data for the first line (black)
0011 %         X2,Y2 are the data for the second line (red)
0012 %         XLABELS is a cell array containing the two x-labels
0013 %         YLABELS is a cell array containing the two y-labels
0014 %
0015 %The optional output handle graphics objects AX,HL1,HL2
0016 %allow the user to easily change the properties of the plot.
0017 %
0018 %Example: Plot temperature T and salinity S
0019 %         as a function of depth D in the ocean
0020 %
0021 %D = linspace(-100,0,50);
0022 %S = linspace(34,32,50);
0023 %T = 10*exp(D/40);
0024 %xlabels{1} = 'Temperature (C)';
0025 %xlabels{2} = 'Salinity';
0026 %ylabels{1} = 'Depth(m)';
0027 %ylabels{2} = 'Depth(m)';
0028 %[ax,hlT,hlS] = plotxx(T,D,S,D,xlabels,ylabels);
0029 
0030 
0031 %The code is inspired from page 10-26 (Multiaxis axes)
0032 %of the manual USING MATLAB GRAPHICS, version 5.
0033 %
0034 %Tested with Matlab 5.3.1 and above on PCWIN
0035 
0036 %Author: Denis Gilbert, Ph.D., physical oceanography
0037 %Maurice Lamontagne Institute, Dept. of Fisheries and Oceans Canada
0038 %email: gilbertd@dfo-mpo.gc.ca  Web: http://www.qc.dfo-mpo.gc.ca/iml/
0039 %November 1997; Last revision: 01-Nov-2001
0040 
0041 if nargin < 4
0042    error('Not enough input arguments')
0043 elseif nargin==4
0044    %Use empty strings for the xlabels
0045    xlabels{1}=' '; xlabels{2}=' '; ylabels{1}=' '; ylabels{2}=' ';
0046 elseif nargin==5
0047    %Use empty strings for the ylabel
0048    ylabels{1}=' '; ylabels{2}=' ';
0049 elseif nargin > 6
0050    error('Too many input arguments')
0051 end
0052 
0053 if length(ylabels) == 1
0054    ylabels{2} = ' ';
0055 end
0056 
0057 if ~iscellstr(xlabels) 
0058    error('Input xlabels must be a cell array')
0059 elseif ~iscellstr(ylabels) 
0060    error('Input ylabels must be a cell array')
0061 end
0062 
0063 hl1=line(x1,y1,'Color','k');
0064 ax(1)=gca;
0065 set(ax(1),'Position',[0.12 0.12 0.75 0.70])
0066 set(ax(1),'XColor','k','YColor','k');
0067 
0068 ax(2)=axes('Position',get(ax(1),'Position'),...
0069    'XAxisLocation','top',...
0070    'YAxisLocation','right',...
0071    'Color','none',...
0072    'XColor','r','YColor','k');
0073 
0074 set(ax,'box','off')
0075 
0076 hl2=line(x2,y2,'Color','r','Parent',ax(2));
0077 
0078 %label the two x-axes
0079 set(get(ax(1),'xlabel'),'string',xlabels{1})
0080 set(get(ax(2),'xlabel'),'string',xlabels{2})
0081 set(get(ax(1),'ylabel'),'string',ylabels{1})
0082 set(get(ax(2),'ylabel'),'string',ylabels{2})

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005