IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
decimate_ticks.m
Go to the documentation of this file.
1 %>@ingroup graphicsapi
2 %>@file
3 %>@brief Removes ticks when there are too many of them
4 %
5 %> @param flags =[1, 1]. Corresponds to [flag_x, flag_y], i.e., whether to act on the respective axis's
6 %> @param maxs =[16, 13]. Maximum numbers of ticks in the x-axis and y-axis respectively
7 function decimate_ticks(flags, maxs)
8 
9 if nargin < 1 || isempty(flags)
10  flags = [1, 1];
11 elseif numel(flags) == 1
12  flags = [flags, 0]; % when only one flag is passed, the y-axis one will be turned off by default
13 end;
14 
15 if nargin < 2 || isempty(maxs)
16  maxs = [16, 13];
17 elseif numel(maxs) == 1
18  maxs = [maxs, 0]; % when only one flag is passed, the y-axis one will be turned off by default
19 end;
20 
21 xy = 'xy';
22 h_ca = gca();
23 for i = 1:2
24  if flags(i)
25  maxticks = maxs(i);
26  stn = xy(i); % string, tick name
27 
28  ticks = get(h_ca, [stn, 'tick']);
29  nf = numel(ticks);
30 
31  no_ins = nf/maxticks;
32  if no_ins > 1
33  ii = round(linspace(1, nf, maxticks));
34 
35  ticklabels = get(h_ca, [stn, 'ticklabel']);
36  ticklabels = ticklabels(ii);
37  ticks = ticks(ii);
38 
39  set(h_ca, [stn, 'tick'], ticks);
40  set(h_ca, [stn, 'ticklabel'], ticklabels);
41  end;
42  end;
43 end;