x_tick_helper.m 772 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. function ht=x_tick_helper(ax,xloc,xtext,varargin)
  2. % ht=x_tick_helper(ax,xloc,xtext,['rot' degrees])
  3. %
  4. % Function to add vertical or angled x tick labels
  5. rot=90;
  6. utils.overridedefaults(who,varargin);
  7. if rot==0
  8. vert_a='top';
  9. horz_a='center';
  10. else
  11. vert_a='middle';
  12. horz_a='left';
  13. end
  14. axes(ax);
  15. curr_tick=get(ax,'XTick');
  16. y_lim=ylim(ax);
  17. y=y_lim(1)-0.08*range(y_lim);
  18. ht=zeros(size(xloc));
  19. keeps=ht==1;
  20. for tx=1:numel(ht)
  21. if ~isempty(xtext{tx})
  22. ht(tx)=text(xloc(tx),y,[xtext{tx}]);
  23. keeps(tx)=1;
  24. end
  25. end
  26. kxloc=xloc(keeps);
  27. new_tick=sort([kxloc(:); curr_tick(:)]);
  28. set(ax,'XTick',new_tick','XTickLabel',[]);
  29. ht=ht(keeps);
  30. set(ht,'Rotation',rot,'VerticalAlignment',vert_a,'HorizontalAlignment',horz_a);
  31. % set(ax,'Units','points');