NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/plots/floataxisx.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function [hl1,ax2,ax3] = floatAxisX(varargin)
2 % floatAxisX  create floating x-axis for multi-parameter plot
3 % =========================================================================
4 % floatAxisX  Version 1.1 31-May-1999
5 %
6 % Usage:
7 %   [h1,ax2,ax3] = floatAxisX(varargin)
8 %
9 % Description:
10 %   This Matlab function creates a floating x-axis for mutli-parameter
11 %   plots with different units on the same figure. For example, in oceanography,
12 %   it is common to plot temperature, salinity, and density versus depth.
13 %
14 %
15 % Input:
16 %   A minimum of two parameters is required. The first and second parameters are
17 %   the x,y pairs to plot. The third parameter (optional) specifies the linestyle
18 %   (defaults to 'k-' solid black). The fourth parameter (optional) specifies the
19 %   x-axis label for the floating axis. The fifth parameter (optional) specifies
20 %   the x and y limits for the axis(this should be of the form
21 %   [xlower xupper ylower yupper]).
22 %
23 % Output:
24 %   n/a
25 %
26 % Called by:
27 %   CTDplotX.m - script to demo floatAxis function
28 %
29 % Calls:
30 %   n/a
31 %
32 % Author:
33 %   Blair Greenan
34 %   Bedford Institute of Oceanography
35 %   18-May-1999
36 %   Matlab 5.2.1
37 %   greenanb@mar.dfo-mpo.gc.ca
38 % =========================================================================
39 %
40
41 % History
42 % Version 1.0 18-May-1999
43 % Version 1.1 31-May-1999
44 %    Added the ability to pass an array containing the x and y limits for
45 %    the axis.
46
47 % strip the arguments passed in
48 if (nargin < 2)
49    error('floatAxis requires a minimum of three parameters')
50 elseif (nargin == 2)
51    x = varargin{1};
52    y = varargin{2};
53    % default lines style (solid black line)
54    lstyle = 'k-';   
55 elseif (nargin == 3)
56    x = varargin{1};
57    y = varargin{2}; 
58    lstyle = varargin{3};
59 elseif (nargin == 4)
60    x = varargin{1};
61    y = varargin{2}; 
62    lstyle = varargin{3};
63    xlbl = varargin{4};
64 elseif (nargin == 5)
65    x = varargin{1};
66    y = varargin{2};
67    lstyle = varargin{3};
68    xlbl = varargin{4};
69    limits = varargin{5};
70 else
71    error('Too many arguments')
72 end
73
74 % get position of axes
75 allAxes = get(gcf,'Children');
76 ax1Pos = get(allAxes(length(allAxes)),'position');
77
78 % rescale and reposition all axes to handle additional axes
79 for ii = 1:length(allAxes)-1
80    if (rem(ii,2)==0)
81       % even ones in array of axes handles represent axes on which lines are plotted
82       set(allAxes(ii),'Position',[ax1Pos(1) ax1Pos(2)+0.1 ax1Pos(3) ax1Pos(4)-0.1])
83    else
84       % odd ones in array of axes handles represent axes on which floating x-axss exist
85       axPos = get(allAxes(ii),'Position');
86       set(allAxes(ii),'Position',[axPos(1) axPos(2)+0.1 axPos(3) axPos(4)])
87    end
88 end
89 % first axis a special case (doesn't fall into even/odd scenario of figure children)
90 set(allAxes(length(allAxes)),'Position',[ax1Pos(1) ax1Pos(2)+0.1 ax1Pos(3) ax1Pos(4)-0.1])
91
92 % get new position for plotting area of figure
93 ax1Pos = get(allAxes(length(allAxes)),'position');
94
95 % axis to which the floating axes will be referenced
96 ref_axis = allAxes(1);
97 refPosition = get(ref_axis,'position');
98
99 % overlay new axes on the existing one
100 ax2 = axes('Position',ax1Pos);
101 % plot data and return handle for the line
102 hl1 = plot(x,y,lstyle);
103 % make the new axes invisible, leaving only the line visible
104 set(ax2,'visible','off')
105
106 if (nargin < 5)
107    % get the x limits for the
108    xlimit = get(ax2,'XLim');
109 else
110    set(ax2,'XLim',[limits(1) limits(2)],'YLim',[limits(3) limits(4)]);
111 end
112
113 % set the axis limit mode so that it does not change if the
114 % user resizes the figure window
115 set(ax2,'xLimMode','manual')
116
117 % set up another set of axes to act as floater
118 ax3 = axes('Position',[refPosition(1) refPosition(2)-0.1 refPosition(3) 0.01]);
119 set(ax3,'box','off','ycolor','w','yticklabel',[],'ytick',[])
120 set(ax3,'XMinorTick','on','color','none','xcolor',get(hl1,'color'))
121 if (nargin < 5)
122    set(ax3,'XLim',xlimit)
123 else
124    set(ax3,'XLim',[limits(1) limits(2)],'YLim',[limits(3) limits(4)])
125 end
126
127 % label the axis
128 if (nargin > 3)
129    xlabel(xlbl)
130 end
131
132
Note: See TracBrowser for help on using the browser.