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

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

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

Initial import of Stark code.

Line 
1 function [hl1,ax2,ax3] = floatAxisY(varargin)
2 % floatAxisY  create floating x-axis for multi-parameter plot
3 % =========================================================================
4 % floatAxisY  Version 1.1 31-May-1999
5 %
6 % Usage:
7 %   [h1,ax2,ax3] = floatAxisY(varargin)
8 %
9 % Description:
10 %   This Matlab function creates a floating y-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 %   CTDplotY.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
48 % strip the arguments passed in
49 if (nargin < 2)
50    error('floatAxis requires a minimum of three parameters')
51 elseif (nargin == 2)
52    x = varargin{1};
53    y = varargin{2};
54    % default lines style (solid black line)
55    lstyle = 'k-';   
56 elseif (nargin == 3)
57    x = varargin{1};
58    y = varargin{2}; 
59    lstyle = varargin{3};
60 elseif (nargin == 4)
61    x = varargin{1};
62    y = varargin{2};
63    lstyle = varargin{3};
64    ylbl = varargin{4};
65 elseif (nargin == 5)
66    x = varargin{1};
67    y = varargin{2};
68    lstyle = varargin{3};
69    ylbl = varargin{4};
70    limits = varargin{5};
71 else
72    error('Too many arguments')
73 end
74
75 % get position of axes
76 allAxes = get(gcf,'Children');
77 ax1Pos = get(allAxes(length(allAxes)),'position');
78
79 % rescale and reposition all axes to handle additional axes
80 for ii = 1:length(allAxes)-1
81    if (rem(ii,2)==0)
82       % even ones in array of axes handles represent axes on which lines are plotted
83       set(allAxes(ii),'Position',[ax1Pos(1)+0.1 ax1Pos(2) ax1Pos(3)-0.1 ax1Pos(4)])
84    else
85       % odd ones in array of axes handles represent axes on which floating x-axss exist
86       axPos = get(allAxes(ii),'Position');
87       set(allAxes(ii),'Position',[axPos(1)+0.1 axPos(2) axPos(3) axPos(4)])
88    end
89 end
90 % first axis a special case (doesn't fall into even/odd scenario of figure children)
91 set(allAxes(length(allAxes)),'Position',[ax1Pos(1)+0.1 ax1Pos(2) ax1Pos(3)-0.1 ax1Pos(4)])
92
93 % get new position for plotting area of figure
94 ax1Pos = get(allAxes(length(allAxes)),'position');
95
96 % axis to which the floating axes will be referenced
97 ref_axis = allAxes(1);
98 refPosition = get(ref_axis,'position');
99
100 % overlay new axes on the existing one
101 ax2 = axes('Position',ax1Pos);
102 % plot data and return handle for the line
103 hl1 = plot(x,y,lstyle);
104 % make the new axes invisible, leaving only the line visible
105 set(ax2,'visible','off')
106
107 if (nargin < 5)
108    % get the y limits for the
109    ylimit = get(ax2,'YLim');
110 else
111    set(ax2,'XLim',[limits(1) limits(2)],'YLim',[limits(3) limits(4)]);
112 end
113
114 % set the axis limit mode so that it does not change if the
115 % user resizes the figure window
116 set(ax2,'YLimMode','manual')
117
118 % set up another set of axes to act as floater
119 ax3 = axes('Position',[refPosition(1)-0.1 refPosition(2) 0.01 refPosition(4)]);
120 set(ax3,'box','off','ycolor','w','xticklabel',[],'xtick',[])
121 set(ax3,'YMinorTick','on','color','none','ycolor',get(hl1,'color'))
122 if (nargin < 5)
123    set(ax3,'YLim',ylimit)
124 else
125    set(ax3,'XLim',[limits(1) limits(2)],'YLim',[limits(3) limits(4)])
126 end
127
128 % label the axis
129 if (nargin > 3)
130    ylabel(ylbl)
131 end
132
133
Note: See TracBrowser for help on using the browser.