1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of zoomfixticks</title> |
---|
6 | <meta name="keywords" content="zoomfixticks"> |
---|
7 | <meta name="description" content="ZOOMFIXTICKS - Allows zoom to work on a figure whose AXES tick labels are manually set"> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../../index.html">Home</a> > <a href="#">applications</a> > <a href="index.html">common</a> > zoomfixticks.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for applications/common <img alt=">" border="0" src="../../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>zoomfixticks |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
24 | <div class="box"><strong>ZOOMFIXTICKS - Allows zoom to work on a figure whose AXES tick labels are manually set</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function zoomfixticks(fig,method,varargin) </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment">ZOOMFIXTICKS - Allows zoom to work on a figure whose AXES tick labels are manually set |
---|
31 | ZOOMFIXTICKS(FIG) operates on the figure with handle FIG. |
---|
32 | ZOOMFIXTICKS(AX) operates on the figure with child AXES handle AX. |
---|
33 | ZOOMFIXTICKS with no arguments operates on the current figure. |
---|
34 | |
---|
35 | Note that when using this function, you will need to modify the FIXTICKS |
---|
36 | subfunction to meet your application needs. Alternatively, you can comment |
---|
37 | out the function and supply it as an M-file function on the MATLAB path. |
---|
38 | If you supply your own, make sure that the M-file is named "fixticks.m", and |
---|
39 | it takes a single input argument, the handle to an AXES object. |
---|
40 | |
---|
41 | Example: |
---|
42 | hf = figure; |
---|
43 | xdata = [0:.01:1]; |
---|
44 | ydata = 100000*sin(2*pi*5*xdata); |
---|
45 | plot(xdata,ydata); |
---|
46 | zoomfixticks(hf) |
---|
47 | |
---|
48 | Greg Aloe (8-8-2002)</pre></div> |
---|
49 | |
---|
50 | <!-- crossreference --> |
---|
51 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
52 | This function calls: |
---|
53 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
54 | </ul> |
---|
55 | This function is called by: |
---|
56 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
57 | </ul> |
---|
58 | <!-- crossreference --> |
---|
59 | |
---|
60 | <h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
61 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
62 | <li><a href="#_sub1" class="code">function init(fig)</a></li><li><a href="#_sub2" class="code">function zoomInCallback(hcbo,fig)</a></li><li><a href="#_sub3" class="code">function zoomOutCallback(hcbo,fig)</a></li><li><a href="#_sub4" class="code">function downFcn(fig)</a></li><li><a href="#_sub5" class="code">function fixticks(ax)</a></li></ul> |
---|
63 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
64 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function zoomfixticks(fig,method,varargin)</a> |
---|
65 | 0002 <span class="comment">%ZOOMFIXTICKS - Allows zoom to work on a figure whose AXES tick labels are manually set</span> |
---|
66 | 0003 <span class="comment">% ZOOMFIXTICKS(FIG) operates on the figure with handle FIG.</span> |
---|
67 | 0004 <span class="comment">% ZOOMFIXTICKS(AX) operates on the figure with child AXES handle AX.</span> |
---|
68 | 0005 <span class="comment">% ZOOMFIXTICKS with no arguments operates on the current figure.</span> |
---|
69 | 0006 <span class="comment">%</span> |
---|
70 | 0007 <span class="comment">% Note that when using this function, you will need to modify the FIXTICKS</span> |
---|
71 | 0008 <span class="comment">% subfunction to meet your application needs. Alternatively, you can comment</span> |
---|
72 | 0009 <span class="comment">% out the function and supply it as an M-file function on the MATLAB path.</span> |
---|
73 | 0010 <span class="comment">% If you supply your own, make sure that the M-file is named "fixticks.m", and</span> |
---|
74 | 0011 <span class="comment">% it takes a single input argument, the handle to an AXES object.</span> |
---|
75 | 0012 <span class="comment">%</span> |
---|
76 | 0013 <span class="comment">% Example:</span> |
---|
77 | 0014 <span class="comment">% hf = figure;</span> |
---|
78 | 0015 <span class="comment">% xdata = [0:.01:1];</span> |
---|
79 | 0016 <span class="comment">% ydata = 100000*sin(2*pi*5*xdata);</span> |
---|
80 | 0017 <span class="comment">% plot(xdata,ydata);</span> |
---|
81 | 0018 <span class="comment">% zoomfixticks(hf)</span> |
---|
82 | 0019 <span class="comment">%</span> |
---|
83 | 0020 <span class="comment">% Greg Aloe (8-8-2002)</span> |
---|
84 | 0021 |
---|
85 | 0022 |
---|
86 | 0023 <span class="comment">% Set up the figure if there are less than 2 arguments</span> |
---|
87 | 0024 <span class="keyword">if</span> nargin < 2 |
---|
88 | 0025 <span class="comment">% Make sure the input is a handle to an AXES or FIGURE</span> |
---|
89 | 0026 <span class="keyword">if</span> nargin==0 |
---|
90 | 0027 <span class="comment">% If no arguments, assume the current figure</span> |
---|
91 | 0028 fig = gcf; |
---|
92 | 0029 <span class="keyword">elseif</span> ishandle(fig) & ~strcmp(lower(get(fig,<span class="string">'type'</span>)),<span class="string">'figure'</span>) |
---|
93 | 0030 <span class="comment">% If FIG is a handle, but not to a figure, assume it's an axes and get its parent</span> |
---|
94 | 0031 fig = get(fig,<span class="string">'parent'</span>); |
---|
95 | 0032 <span class="keyword">end</span> |
---|
96 | 0033 |
---|
97 | 0034 <span class="comment">% Error out if the input is not a handle, or not a handle to a figure or axes</span> |
---|
98 | 0035 <span class="keyword">if</span> ~ishandle(fig) | (ishandle(fig) & ~strcmp(lower(get(fig,<span class="string">'type'</span>)),<span class="string">'figure'</span>)) |
---|
99 | 0036 error(<span class="string">'Input argument must be a handle to an AXES or FIGURE object.'</span>) |
---|
100 | 0037 <span class="keyword">end</span> |
---|
101 | 0038 |
---|
102 | 0039 <span class="comment">% Initialize the setup of the figure</span> |
---|
103 | 0040 <a href="#_sub1" class="code" title="subfunction init(fig)">init</a>(fig) |
---|
104 | 0041 <span class="keyword">else</span> |
---|
105 | 0042 <span class="comment">% if 2 or more arguments, perform the desired operation</span> |
---|
106 | 0043 feval(method,varargin{:}) |
---|
107 | 0044 <span class="keyword">end</span> |
---|
108 | 0045 |
---|
109 | 0046 |
---|
110 | 0047 <span class="comment">%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span> |
---|
111 | 0048 <a name="_sub1" href="#_subfunctions" class="code">function init(fig)</a> |
---|
112 | 0049 <span class="comment">% This function sets up the figure so that zooms will work even when the AXES</span> |
---|
113 | 0050 <span class="comment">% ticklabels are set manually</span> |
---|
114 | 0051 |
---|
115 | 0052 <span class="comment">% Change the callback for the "Zoom In" toolbar button</span> |
---|
116 | 0053 hin = findall(fig,<span class="string">'tag'</span>,<span class="string">'figToolZoomIn'</span>); |
---|
117 | 0054 set(hin,<span class="string">'ClickedCallback'</span>,<span class="string">'zoomfixticks(gcbf,''zoomInCallback'',gcbo,gcbf)'</span>) |
---|
118 | 0055 |
---|
119 | 0056 <span class="comment">% Change the callback for the "Zoom Out" toolbar button</span> |
---|
120 | 0057 hout = findall(fig,<span class="string">'tag'</span>,<span class="string">'figToolZoomOut'</span>); |
---|
121 | 0058 set(hout,<span class="string">'ClickedCallback'</span>,<span class="string">'zoomfixticks(gcbf,''zoomOutCallback'',gcbo,gcbf)'</span>) |
---|
122 | 0059 |
---|
123 | 0060 <span class="comment">% Fix the ticks on initialization</span> |
---|
124 | 0061 <a href="#_sub5" class="code" title="subfunction fixticks(ax)">fixticks</a>(gca(fig)) |
---|
125 | 0062 |
---|
126 | 0063 <span class="comment">%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span> |
---|
127 | 0064 <a name="_sub2" href="#_subfunctions" class="code">function zoomInCallback(hcbo,fig)</a> |
---|
128 | 0065 <span class="comment">% Callback for the "Zoom In" button</span> |
---|
129 | 0066 |
---|
130 | 0067 <span class="comment">% First call what is normally called during a zoom in</span> |
---|
131 | 0068 putdowntext(<span class="string">'zoomin'</span>,hcbo) |
---|
132 | 0069 |
---|
133 | 0070 <span class="comment">% If the button is depressed, force WindowButtonDownFcn to call the DOWNFCN subfunction</span> |
---|
134 | 0071 <span class="keyword">if</span> strcmp(get(hcbo,<span class="string">'state'</span>),<span class="string">'on'</span>) |
---|
135 | 0072 set(fig,<span class="string">'WindowButtonDownFcn'</span>,<span class="string">'zoomfixticks(gcbf,''downFcn'',gcbf)'</span>) |
---|
136 | 0073 <span class="keyword">end</span> |
---|
137 | 0074 |
---|
138 | 0075 |
---|
139 | 0076 <span class="comment">%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span> |
---|
140 | 0077 <a name="_sub3" href="#_subfunctions" class="code">function zoomOutCallback(hcbo,fig)</a> |
---|
141 | 0078 <span class="comment">% Callback for the "Zoom Out" button</span> |
---|
142 | 0079 |
---|
143 | 0080 <span class="comment">% First call what is normally called during a zoom out</span> |
---|
144 | 0081 putdowntext(<span class="string">'zoomout'</span>,hcbo) |
---|
145 | 0082 |
---|
146 | 0083 <span class="comment">% If the button is depressed, force WindowButtonDownFcn to call the DOWNFCN subfunction</span> |
---|
147 | 0084 <span class="keyword">if</span> strcmp(get(hcbo,<span class="string">'state'</span>),<span class="string">'on'</span>) |
---|
148 | 0085 set(fig,<span class="string">'WindowButtonDownFcn'</span>,<span class="string">'zoomfixticks(gcbf,''downFcn'',gcbf)'</span>) |
---|
149 | 0086 <span class="keyword">end</span> |
---|
150 | 0087 |
---|
151 | 0088 |
---|
152 | 0089 <span class="comment">%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span> |
---|
153 | 0090 <a name="_sub4" href="#_subfunctions" class="code">function downFcn(fig)</a> |
---|
154 | 0091 <span class="comment">% Since the button was pressed, tell the figure that we are starting a zoom</span> |
---|
155 | 0092 zoom(fig,<span class="string">'down'</span>); |
---|
156 | 0093 |
---|
157 | 0094 <span class="comment">% After the zoom, fix the ticks</span> |
---|
158 | 0095 <a href="#_sub5" class="code" title="subfunction fixticks(ax)">fixticks</a>(gca(fig)) |
---|
159 | 0096 |
---|
160 | 0097 |
---|
161 | 0098 <span class="comment">%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span> |
---|
162 | 0099 <a name="_sub5" href="#_subfunctions" class="code">function fixticks(ax)</a> |
---|
163 | 0100 <span class="comment">% This function will perform the desired ticklabel fixing</span> |
---|
164 | 0101 <span class="comment">% This is the function you will want to modify to meet your application needs</span> |
---|
165 | 0102 <span class="comment">% Alternatively, you can comment out this function to call an M-file function</span> |
---|
166 | 0103 <span class="comment">% in its place.</span> |
---|
167 | 0104 |
---|
168 | 0105 <span class="comment">% EXAMPLE:</span> |
---|
169 | 0106 <span class="comment">% First update the axes so the ticks are as expected</span> |
---|
170 | 0107 drawnow |
---|
171 | 0108 <span class="comment">% Get the ticks</span> |
---|
172 | 0109 tick=get(ax,<span class="string">'ytick'</span>); |
---|
173 | 0110 <span class="comment">% Convert ticks to a string of the desired format</span> |
---|
174 | 0111 tickstr=num2str(tick',7); |
---|
175 | 0112 <span class="comment">% Reset the labels to the new format</span> |
---|
176 | 0113 set(ax,<span class="string">'yticklabel'</span>,tickstr);</pre></div> |
---|
177 | <hr><address>Generated on Mon 21-May-2007 15:32:41 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
178 | </body> |
---|
179 | </html> |
---|