0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 function [hx,hy] = ...
0097 format_ticks(h,tickx,ticky,tickposx,tickposy,rotx,roty,offset,varargin)
0098
0099
0100 if ~exist('offset','var');
0101 offset = 0.02;
0102 elseif length(offset) == 0;
0103 offset = 0.02;
0104 end;
0105
0106
0107 if ~exist('h','var');
0108 h = gca;
0109 warning(['Axis handle NOT Input, Defaulting to Current Axes, '...
0110 num2str(h)]);
0111 elseif length(h) == 0;
0112 h = gca;
0113 warning(['Axis Handle NOT Input, Defaulting to Current Axes, '...
0114 num2str(h)]);
0115 elseif ~ishandle(h(1))
0116 warning(['Input (' num2str(h(1)) ') is NOT an axis handle, ' ...
0117 'defaulting to current axis, ' num2str(h)]);
0118 h = gca;
0119 end;
0120
0121
0122
0123
0124
0125 if length(get(h,'XTickLabel'))==0;
0126 set(h,'XTickLabel',get(h,'XTick'));
0127 end;
0128
0129 if exist('tickposx','var');
0130 if length(tickposx) > 0;
0131 set(h,'XTick',tickposx);
0132 end;
0133 tickposx = get(h,'XTick');
0134 set(h,'XTickLabel',tickposx);
0135 end;
0136
0137 if exist('tickposx','var');
0138 if length(tickposx) > 0;
0139 lim = get(h,'XLim');
0140 if lim(1) > min(tickposx);
0141 lim(1) = min(tickposx);
0142 end;
0143 if lim(2) < max(tickposx);
0144 lim(2) = max(tickposx);
0145 end;
0146 set(h,'XLim',lim);
0147 end;
0148 end;
0149
0150 if ~exist('tickx','var');
0151 tickx = get(h,'XTickLabel');
0152 if ischar(tickx);
0153 temp = tickx;
0154 tickx = cell(1,size(temp,1));
0155 for j=1:size(temp,1);
0156 tickx{j} = strtrim( temp(j,:) );
0157 end;
0158 end;
0159 append = '^{\circ}';
0160 for j=1:length(tickx);
0161 tickx{j} = [tickx{j} append];
0162 end;
0163 elseif length(tickx) == 0;
0164 tickx = get(h,'XTickLabel');
0165 if ischar(tickx);
0166 temp = tickx;
0167 tickx = cell(1,size(temp,1));
0168 for j=1:size(temp,1);
0169 tickx{j} = strtrim( temp(j,:) );
0170 end;
0171 end;
0172 append = '^{\circ}';
0173 for j=1:length(tickx);
0174 tickx{j} = [tickx{j} append];
0175 end;
0176 elseif isstr(tickx);
0177 append = tickx;
0178 tickx = get(h,'XTickLabel');
0179 if ischar(tickx);
0180 temp = tickx;
0181 tickx = cell(1,size(temp,1));
0182 for j=1:size(temp,1);
0183 tickx{j} = strtrim( temp(j,:) );
0184 end;
0185 end;
0186 if strcmp(append(1),'$');
0187 for j=1:length(tickx);
0188 tickx{j} = ['$' tickx{j} append(2:end)];
0189 end;
0190 else;
0191 for j=1:length(tickx);
0192 tickx{j} = [tickx{j} append];
0193 end;
0194 end;
0195 elseif ~iscell(tickx );
0196 warning(['Input TICKX variable is not a compatible string ' ...
0197 'or cell array! Returning...']);
0198 return;
0199 end;
0200
0201 temp = tickx{1};
0202 if strcmp(temp(1),'$');
0203 latex_on = 1;
0204 else;
0205 latex_on = 0;
0206 end;
0207
0208 set(h,'XTickLabel',{});
0209
0210 if ~exist('tickposx','var');
0211 tickposx = get(h,'XTick');
0212 elseif length(tickx) == 0;
0213 tickposx = get(h,'XTick');
0214 end;
0215
0216 if ~exist('tickposy','var');
0217 tickposy = get(h,'YTick');
0218 elseif length(tickposy) == 0;
0219 tickposy = get(h,'YTick');
0220 end;
0221
0222 set(h,'YTick',tickposy);
0223 set(h,'XTick',tickposx);
0224
0225 l1 = length(tickx);
0226 l2 = length(tickposx);
0227 if l1==0;
0228 set(h,'XTickLabel',tickx);
0229 end;
0230 if l1~=l2;
0231 disp(['Length of XTick = ' num2str(length(tickposx))]);
0232 disp(['Length of XTickLabel = ' num2str(length(tickx))]);
0233 if l2 < l1;
0234 warning(['Reducing Length of XTickLabel!']);
0235 else;
0236 warning(['Reducing Length of XTick!']);
0237 end;
0238 l3 = min([l1,l2]);
0239
0240
0241 tickx = tickx{1:l3};
0242 tickposx = tickposx(1:l3);
0243 end;
0244
0245 if ~exist('rotx','var');
0246 rotx = 0;
0247 elseif length(rotx) == 0;
0248 rotx = 0;
0249 end;
0250
0251
0252 tickx = cellstr(tickx);
0253
0254 lim = get(h,'YLim');
0255 if min(tickposy) < lim(1);
0256 lim(1) = min(tickposy);
0257 end;
0258 if max(tickposy) > lim(2);
0259 lim(2) = max(tickposy);
0260 end;
0261 if rotx == 0;
0262 if latex_on;
0263 hx = text(tickposx,...
0264 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposx),1),...
0265 tickx,'HorizontalAlignment','center',...
0266 'VerticalAlignment','top','rotation',rotx,'interpreter','LaTex');
0267 else;
0268 hx = text(tickposx,...
0269 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposx),1),...
0270 tickx,'HorizontalAlignment','center',...
0271 'VerticalAlignment','top','rotation',rotx);
0272 end;
0273 elseif rotx < 0;
0274 if latex_on;
0275 hx = text(tickposx,...
0276 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposx),1),...
0277 tickx,'HorizontalAlignment','left','interpreter','LaTex',...
0278 'VerticalAlignment','middlefi','rotation',rotx);
0279 else;
0280 hx = text(tickposx,...
0281 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposx),1),...
0282 tickx,'HorizontalAlignment','left',...
0283 'VerticalAlignment','middle','rotation',rotx);
0284 end;
0285 else;
0286 if latex_on;
0287 hx = text(tickposx,...
0288 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposx),1),...
0289 tickx,'HorizontalAlignment','right','interpreter','LaTex',...
0290 'VerticalAlignment','middle','rotation',rotx);
0291 else;
0292 hx = text(tickposx,...
0293 repmat(lim(1)-offset*(lim(2)-lim(2)),length(tickposx),1),...
0294 tickx,'HorizontalAlignment','right',...
0295 'VerticalAlignment','middle','rotation',rotx);
0296 end;
0297 end;
0298
0299 set(hx,'FontSize',get(h,'FontSize'));
0300 set(hx,'FontWeight',get(h,'FontWeight'));
0301
0302
0303 if length(varargin) > 2;
0304 command_string = ['set(hx'];
0305 for j=1:2:length(varargin);
0306 command_string = [command_string ',' ...
0307 '''' varargin{j} ''',varargin{' num2str(j+1) '}'];
0308 end;
0309 command_string = [command_string ');'];
0310 eval(command_string);
0311 end;
0312
0313
0314
0315 hxlabel=get(h,'xlabel');
0316 if ~isempty(get(hxlabel,'string'))
0317 set(hx,'unit','points');
0318 tkext=median(cell2mat(get(hx,'Extent')));
0319 set(hx,'unit','data');
0320 set(hxlabel,'unit','points');
0321 xlpos=get(hxlabel,'Position');
0322 set(hxlabel, 'Position',[xlpos(1), xlpos(2)-tkext(4)]);
0323 end
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334 if ~exist('ticky');
0335 hy = -1;
0336 elseif length(ticky)==0;
0337 hy = -1;
0338 else;
0339
0340 if length(get(h,'YTickLabel'))==0;
0341 set(h,'YTickLabel',get(h,'YTick'));
0342 end;
0343
0344 if exist('tickposy','var');
0345 if length(tickposy) > 0;
0346 set(h,'YTick',tickposy);
0347 set(h,'YTickLabel',tickposy);
0348 end;
0349 end;
0350
0351 if exist('tickposy','var');
0352 if length(tickposy) > 0;
0353 lim = get(h,'YLim');
0354 if lim(1) > min(tickposy);
0355 lim(1) = min(tickposy);
0356 end;
0357 if lim(2) < max(tickposy);
0358 lim(2) = max(tickposy);
0359 end;
0360 set(h,'YLim',lim);
0361 end;
0362 end;
0363
0364 if ~exist('ticky','var');
0365 ticky = get(h,'YTickLabel');
0366 if ischar(ticky);
0367 temp = ticky;
0368 ticky = cell(1,size(temp,1));
0369 for j=1:size(temp,1);
0370 ticky{j} = strtrim( temp(j,:) );
0371 end;
0372 end;
0373 append = '^{\circ}';
0374 for j=1:length(ticky);
0375 ticky{j} = [ticky{j} append];
0376 end;
0377 elseif length(ticky) == 0;
0378 ticky = get(h,'YTickLabel');
0379 if ischar(ticky);
0380 temp = ticky;
0381 ticky = cell(1,size(temp,1));
0382 for j=1:size(temp,1);
0383 ticky{j} = strtrim( temp(j,:) );
0384 end;
0385 end;
0386 append = '^{\circ}';
0387 for j=1:length(ticky);
0388 ticky{j} = [ticky{j} append];
0389 end;
0390 elseif isstr(ticky);
0391 append = ticky;
0392 ticky = get(h,'YTickLabel');
0393 if ischar(ticky);
0394 temp = ticky;
0395 ticky = cell(1,size(temp,1));
0396 for j=1:size(temp,1);
0397 ticky{j} = strtrim( temp(j,:) );
0398 end;
0399 end;
0400 if strcmp(append(1),'$');
0401 for j=1:length(ticky);
0402 ticky{j} = ['$' ticky{j} append(2:end)];
0403 end;
0404 else;
0405 for j=1:length(ticky);
0406 ticky{j} = [ticky{j} append];
0407 end;
0408 end;
0409 elseif ~iscell(ticky );
0410 warning(['Input TICKY variable is not a compatible string ' ...
0411 'or cell array! Returning...']);
0412 return;
0413 end;
0414
0415 temp = ticky{1};
0416 if strcmp(temp(1),'$');
0417 latex_on = 1;
0418 else;
0419 latex_on = 0;
0420 end;
0421
0422 set(h,'YTickLabel',{});
0423
0424 if ~exist('tickposy','var');
0425 tickposy = get(h,'YTick');
0426 elseif length(ticky) == 0;
0427 tickposy = get(h,'YTick');
0428 end;
0429
0430 if ~exist('tickposx','var');
0431 tickposx = get(h,'YTick');
0432 elseif length(tickposx) == 0;
0433 tickposx = get(h,'XTick');
0434 end;
0435
0436 set(h,'YTick',tickposy);
0437
0438
0439 l1 = length(ticky);
0440 l2 = length(tickposy);
0441 if l1==0;
0442 set(h,'YTickLabel',ticky);
0443 end;
0444 if l1~=l2;
0445 disp(['Length of YTick = ' num2str(length(tickposy))]);
0446 disp(['Length of YTickLabel = ' num2str(length(ticky))]);
0447 if l2 < l1;
0448 warning(['Reducing Length of YTickLabel!']);
0449 else;
0450 warning(['Reducing Length of YTick!']);
0451 end;
0452 l3 = min([l1,l2]);
0453 ticky = ticky{1:l3};
0454 tickposy = tickposy(1:l3);
0455 end;
0456
0457 if ~exist('roty','var');
0458 roty = 0;
0459 elseif length(roty) == 0;
0460 roty = 0;
0461 end;
0462
0463
0464 ticky = cellstr(ticky);
0465
0466 lim = get(h,'XLim');
0467 if min(tickposx) < lim(1);
0468 lim(1) = min(tickposx);
0469 end;
0470 if max(tickposx) > lim(2);
0471 lim(2) = max(tickposx);
0472 end;
0473 if roty == 0;
0474 if latex_on;
0475 hy = text(...
0476 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposy),1),...
0477 tickposy,...
0478 ticky,'VerticalAlignment','middle',...
0479 'HorizontalAlignment','right','rotation',roty,'interpreter','LaTex');
0480 else;
0481 hy = text(...
0482 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposy),1),...
0483 tickposy,...
0484 ticky,'VerticalAlignment','middle',...
0485 'HorizontalAlignment','right','rotation',roty);
0486 end;
0487 elseif roty < 180;
0488 if latex_on;
0489 hy = text(...
0490 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposy),1),...
0491 tickposy,...
0492 ticky,'VerticalAlignment','middle',...
0493 'HorizontalAlignment','right','rotation',roty,'interpreter','LaTex');
0494 else;
0495 hy = text(...
0496 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposy),1),...
0497 tickposy,...
0498 ticky,'VerticalAlignment','middle',...
0499 'HorizontalAlignment','right','rotation',roty);
0500 end;
0501 else;
0502 if latex_on;
0503 hy = text(...
0504 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposy),1),...
0505 tickposy,...
0506 ticky,'VerticalAlignment','middle',...
0507 'HorizontalAlignment','right','rotation',roty,'interpreter','LaTex');
0508 else;
0509 hy = text(...
0510 repmat(lim(1)-offset*(lim(2)-lim(1)),length(tickposy),1),...
0511 tickposy,...
0512 ticky,'VerticalAlignment','middle',...
0513 'HorizontalAlignment','right','rotation',roty);
0514 end;
0515 end;
0516
0517 set(hy,'FontSize',get(h,'FontSize'));
0518 set(hy,'FontWeight',get(h,'FontWeight'));
0519
0520
0521 if length(varargin) > 2;
0522 command_string = ['set(hy'];
0523 for j=1:2:length(varargin);
0524 command_string = [command_string ',' ...
0525 '''' varargin{j} ''',varargin{' num2str(j+1) '}'];
0526 end;
0527 command_string = [command_string ');'];
0528 eval(command_string);
0529 end;
0530 end;
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576