ZOOMFIXTICKS - Allows zoom to work on a figure whose AXES tick labels are manually set ZOOMFIXTICKS(FIG) operates on the figure with handle FIG. ZOOMFIXTICKS(AX) operates on the figure with child AXES handle AX. ZOOMFIXTICKS with no arguments operates on the current figure. Note that when using this function, you will need to modify the FIXTICKS subfunction to meet your application needs. Alternatively, you can comment out the function and supply it as an M-file function on the MATLAB path. If you supply your own, make sure that the M-file is named "fixticks.m", and it takes a single input argument, the handle to an AXES object. Example: hf = figure; xdata = [0:.01:1]; ydata = 100000*sin(2*pi*5*xdata); plot(xdata,ydata); zoomfixticks(hf) Greg Aloe (8-8-2002)
0001 function zoomfixticks(fig,method,varargin) 0002 %ZOOMFIXTICKS - Allows zoom to work on a figure whose AXES tick labels are manually set 0003 % ZOOMFIXTICKS(FIG) operates on the figure with handle FIG. 0004 % ZOOMFIXTICKS(AX) operates on the figure with child AXES handle AX. 0005 % ZOOMFIXTICKS with no arguments operates on the current figure. 0006 % 0007 % Note that when using this function, you will need to modify the FIXTICKS 0008 % subfunction to meet your application needs. Alternatively, you can comment 0009 % out the function and supply it as an M-file function on the MATLAB path. 0010 % If you supply your own, make sure that the M-file is named "fixticks.m", and 0011 % it takes a single input argument, the handle to an AXES object. 0012 % 0013 % Example: 0014 % hf = figure; 0015 % xdata = [0:.01:1]; 0016 % ydata = 100000*sin(2*pi*5*xdata); 0017 % plot(xdata,ydata); 0018 % zoomfixticks(hf) 0019 % 0020 % Greg Aloe (8-8-2002) 0021 0022 0023 % Set up the figure if there are less than 2 arguments 0024 if nargin < 2 0025 % Make sure the input is a handle to an AXES or FIGURE 0026 if nargin==0 0027 % If no arguments, assume the current figure 0028 fig = gcf; 0029 elseif ishandle(fig) & ~strcmp(lower(get(fig,'type')),'figure') 0030 % If FIG is a handle, but not to a figure, assume it's an axes and get its parent 0031 fig = get(fig,'parent'); 0032 end 0033 0034 % Error out if the input is not a handle, or not a handle to a figure or axes 0035 if ~ishandle(fig) | (ishandle(fig) & ~strcmp(lower(get(fig,'type')),'figure')) 0036 error('Input argument must be a handle to an AXES or FIGURE object.') 0037 end 0038 0039 % Initialize the setup of the figure 0040 init(fig) 0041 else 0042 % if 2 or more arguments, perform the desired operation 0043 feval(method,varargin{:}) 0044 end 0045 0046 0047 %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0048 function init(fig) 0049 % This function sets up the figure so that zooms will work even when the AXES 0050 % ticklabels are set manually 0051 0052 % Change the callback for the "Zoom In" toolbar button 0053 hin = findall(fig,'tag','figToolZoomIn'); 0054 set(hin,'ClickedCallback','zoomfixticks(gcbf,''zoomInCallback'',gcbo,gcbf)') 0055 0056 % Change the callback for the "Zoom Out" toolbar button 0057 hout = findall(fig,'tag','figToolZoomOut'); 0058 set(hout,'ClickedCallback','zoomfixticks(gcbf,''zoomOutCallback'',gcbo,gcbf)') 0059 0060 % Fix the ticks on initialization 0061 fixticks(gca(fig)) 0062 0063 %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0064 function zoomInCallback(hcbo,fig) 0065 % Callback for the "Zoom In" button 0066 0067 % First call what is normally called during a zoom in 0068 putdowntext('zoomin',hcbo) 0069 0070 % If the button is depressed, force WindowButtonDownFcn to call the DOWNFCN subfunction 0071 if strcmp(get(hcbo,'state'),'on') 0072 set(fig,'WindowButtonDownFcn','zoomfixticks(gcbf,''downFcn'',gcbf)') 0073 end 0074 0075 0076 %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0077 function zoomOutCallback(hcbo,fig) 0078 % Callback for the "Zoom Out" button 0079 0080 % First call what is normally called during a zoom out 0081 putdowntext('zoomout',hcbo) 0082 0083 % If the button is depressed, force WindowButtonDownFcn to call the DOWNFCN subfunction 0084 if strcmp(get(hcbo,'state'),'on') 0085 set(fig,'WindowButtonDownFcn','zoomfixticks(gcbf,''downFcn'',gcbf)') 0086 end 0087 0088 0089 %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0090 function downFcn(fig) 0091 % Since the button was pressed, tell the figure that we are starting a zoom 0092 zoom(fig,'down'); 0093 0094 % After the zoom, fix the ticks 0095 fixticks(gca(fig)) 0096 0097 0098 %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0099 function fixticks(ax) 0100 % This function will perform the desired ticklabel fixing 0101 % This is the function you will want to modify to meet your application needs 0102 % Alternatively, you can comment out this function to call an M-file function 0103 % in its place. 0104 0105 % EXAMPLE: 0106 % First update the axes so the ticks are as expected 0107 drawnow 0108 % Get the ticks 0109 tick=get(ax,'ytick'); 0110 % Convert ticks to a string of the desired format 0111 tickstr=num2str(tick',7); 0112 % Reset the labels to the new format 0113 set(ax,'yticklabel',tickstr);